Exemple #1
0
class MegaTable(Table):
    """
    A table containing all of the column types, and different column kwargs.
    """

    bigint_col = BigInt()
    boolean_col = Boolean()
    bytea_col = Bytea()
    date_col = Date()
    foreignkey_col = ForeignKey(SmallTable)
    integer_col = Integer()
    interval_col = Interval()
    json_col = JSON()
    jsonb_col = JSONB()
    numeric_col = Numeric(digits=(5, 2))
    real_col = Real()
    double_precision_col = DoublePrecision()
    smallint_col = SmallInt()
    text_col = Text()
    timestamp_col = Timestamp()
    timestamptz_col = Timestamptz()
    uuid_col = UUID()
    varchar_col = Varchar()

    unique_col = Varchar(unique=True)
    null_col = Varchar(null=True)
    not_null_col = Varchar(null=False)
 def test_column_type_conversion_json(self):
     self._test_migrations(table_snapshots=[[self.table(column)]
                                            for column in [
                                                JSON(),
                                                JSONB(),
                                                JSON(),
                                            ]])
    def test_convert_json(self):
        """
        Make sure Python objects are serialised correctly to JSON strings.
        """
        self.assertEqual(
            convert_to_sql_value(value={"a": 123}, column=JSON()).replace(
                " ", ""
            ),
            '{"a":123}',
        )

        self.assertEqual(
            convert_to_sql_value(value={"a": 123}, column=JSONB()).replace(
                " ", ""
            ),
            '{"a":123}',
        )
 def test_jsonb_column(self):
     self._test_migrations(
         table_snapshots=[[self.table(column)] for column in [
             JSONB(),
             JSONB(default=["a", "b", "c"]),
             JSONB(default={"name": "bob"}),
             JSONB(default='{"name": "Sally"}'),
             JSONB(null=True, default=None),
             JSONB(null=False),
         ]],
         test_function=lambda x: all([
             x.data_type == "jsonb",
             x.is_nullable == "NO",
             x.column_default == "'{}'::jsonb",
         ]),
     )
Exemple #5
0
class MegaTable(Table):
    """
    A table containing all of the column types, and different column kwargs.
    """

    array_col = Array(Varchar())
    bigint_col = BigInt()
    boolean_col = Boolean()
    bytea_col = Bytea()
    date_col = Date()
    double_precision_col = DoublePrecision()
    integer_col = Integer()
    interval_col = Interval()
    json_col = JSON()
    jsonb_col = JSONB()
    numeric_col = Numeric(digits=(5, 2))
    real_col = Real()
    smallint_col = SmallInt()
    text_col = Text()
    timestamp_col = Timestamp()
    timestamptz_col = Timestamptz()
    uuid_col = UUID()
    varchar_col = Varchar()
Exemple #6
0
class RecordingStudio(Table):
    name = Varchar()
    facilities = JSONB(null=True)
Exemple #7
0
class MyTable(Table):
    json = JSONB()
 class MyTable(Table):
     column_a = JSON()
     column_b = JSONB()