Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONB (JSON) and UUID column support? [.drift] [Postgres] #2802

Open
tgrushka opened this issue Dec 21, 2023 · 1 comment
Open

JSONB (JSON) and UUID column support? [.drift] [Postgres] #2802

tgrushka opened this issue Dec 21, 2023 · 1 comment
Labels
area-analyzer Related to analyzing code in drift_dev backend-postgres Related to drift_postgres enhancement New feature or request package-drift_dev Affects the drift_dev package

Comments

@tgrushka
Copy link

tgrushka commented Dec 21, 2023

Is your feature request related to a problem? Please describe.
I am using drift_postgres and want to create JSONB (preferably over JSON) and also UUID columns in .drift file SQL definitions.

Describe the solution you'd like

CREATE TABLE IF NOT EXISTS [members] (
    [id] UUID PRIMARY KEY NOT NULL, -- <-- UUID results in double
    [first_name] TEXT NOT NULL,
    [middle_name] TEXT,
    [last_name] TEXT NOT NULL,
    [email] TEXT,
    [phone] TEXT,
    [address] JSONB, -- <-- JSONB results in double
    [created] TIMESTAMP NOT NULL,
    [updated] TIMESTAMP NOT NULL
);

This .drift SQL results in double typed columns:

  late final GeneratedColumn<double> id = GeneratedColumn<double>(
      'id', aliasedName, false,
      type: DriftSqlType.double,
      requiredDuringInsert: true,
      $customConstraints: 'PRIMARY KEY NOT NULL');
...
  late final GeneratedColumn<double> address = GeneratedColumn<double>(
      'address', aliasedName, true,
      type: DriftSqlType.double,
      requiredDuringInsert: false,
      $customConstraints: '');

I also tried JSON:

CREATE TABLE IF NOT EXISTS [members] (
...
    [address] JSON, -- <-- results in error
...
);

and received the following build error:

line 8, column 19: Expected a JSON KEY constraint
  ╷
8 │     [address] JSON,
  │                   ^
  ╵

generated on line 2674 of package:sqlparser-0.33.0/lib/src/reader/parser.dart.

But I would prefer JSONB as that is now the new, "comparable" PostgreSQL JSON type.

I think I have to just use manual Dart Table definitions for now for Postgres.

Thanks!

@tgrushka tgrushka added the enhancement New feature or request label Dec 21, 2023
@simolus3
Copy link
Owner

Drift files are targeting the sqlite3 dialect only at the moment, but you can use this syntax to use custom types. I agree that having builtin support for custom types under their name would be nice though.

@simolus3 simolus3 added backend-postgres Related to drift_postgres package-drift_dev Affects the drift_dev package area-analyzer Related to analyzing code in drift_dev labels Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Related to analyzing code in drift_dev backend-postgres Related to drift_postgres enhancement New feature or request package-drift_dev Affects the drift_dev package
Projects
None yet
Development

No branches or pull requests

2 participants