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

Could not able to use WITH & AS keyword together in .drfit file #2817

Open
Vedsaga opened this issue Jan 2, 2024 · 2 comments
Open

Could not able to use WITH & AS keyword together in .drfit file #2817

Vedsaga opened this issue Jan 2, 2024 · 2 comments
Labels
area-analyzer Related to analyzing code in drift_dev enhancement New feature or request package-drift_dev Affects the drift_dev package

Comments

@Vedsaga
Copy link

Vedsaga commented Jan 2, 2024

Describe the bug

Steps

  1. Create a dart class model
import 'package:freezed_annotation/freezed_annotation.dart';

part 'row_meta_data.freezed.dart';

@freezed
class RowMetaData with _$RowMetaData {
  const factory RowMetaData({
    required int id,
    required DateTime updated,
    required DateTime created,
  }) = _RowMetaData;
}
  1. Create a drift file
-- import starts
import 'package:main/main.dart';
-- import ends

-- Create profile table
CREATE TABLE IF NOT EXISTS profile (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    created DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    dob DATE NOT NULL
) WITH RowMetaData AS ProfileTable;

Actual

// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'app_db.dart';

// ignore_for_file: type=lint
class Profile extends Table with TableInfo<Profile, RowMetaData> {
...
}

Expected

Generated class should have the applied both CustomRow & table name to ProfileTable override.

However it does not as it seems. TableInfo only support two generic annotations, <TableDsl extends Table, D>

mixin TableInfo<TableDsl extends Table, D> on Table implements DatabaseSchemaEntity, ResultSetImplementation<TableDsl, D>

So, only able to use AS or WITH keyword.

@simolus3
Copy link
Owner

simolus3 commented Jan 2, 2024

AS controls the name of the row class, so it can't be combined with WITH (which prevents row classes from being generated altogether).

There is no reliable way to control the name of the generated table name at the moment. I'll think about how to do this - perhaps we need an annotation system in drift files as well.

@simolus3 simolus3 added the enhancement New feature or request label Jan 2, 2024
@greenking19
Copy link

@simolus3
I am currently facing this issue as well. 🙋
I have a lot of table fields and don't want to write my own Dart Table.
May I use build_runner to translate the drift file into a dart file and then copy it over for use?

@simolus3 simolus3 added 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 enhancement New feature or request package-drift_dev Affects the drift_dev package
Projects
None yet
Development

No branches or pull requests

3 participants