From 8161d963235dd21acc96d813be65ddc26706816c Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Wed, 20 Sep 2023 21:42:23 +0800 Subject: [PATCH 1/7] feat: Add getter actualTableNameStatic --- drift_dev/lib/src/writer/tables/table_writer.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drift_dev/lib/src/writer/tables/table_writer.dart b/drift_dev/lib/src/writer/tables/table_writer.dart index 388b58b8d..b8bb82157 100644 --- a/drift_dev/lib/src/writer/tables/table_writer.dart +++ b/drift_dev/lib/src/writer/tables/table_writer.dart @@ -409,7 +409,9 @@ class TableWriter extends TableOrViewWriter { ..write('@override\nString get aliasedName => ' '_alias ?? \'${table.id.name}\';\n') ..write( - '@override\n String get actualTableName => \'${table.id.name}\';\n'); + '@override\n String get actualTableName => \'${table.id.name}\';\n') + ..write( + 'static String get actualTableNameStatic => \'${table.id.name}\';\n'); _writeValidityCheckMethod(); _writePrimaryKeyOverride(); From 0176dac2e6a394e7f75c4f0e3c8365d11f9cc2ad Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Wed, 20 Sep 2023 21:56:07 +0800 Subject: [PATCH 2/7] chore: Run build runner --- docs/lib/snippets/modular/drift/example.drift.dart | 2 ++ drift/example/main.g.dart | 2 ++ drift/test/generated/custom_tables.g.dart | 7 +++++++ drift/test/generated/todos.g.dart | 6 ++++++ drift/test/integration_tests/regress_2166_test.g.dart | 1 + examples/migrations_example/lib/database.g.dart | 3 +++ examples/modular/lib/src/posts.drift.dart | 2 ++ examples/modular/lib/src/search.drift.dart | 1 + examples/modular/lib/src/users.drift.dart | 2 ++ examples/web_worker_example/lib/database.g.dart | 1 + examples/with_built_value/lib/database.drift.dart | 1 + extras/benchmarks/lib/src/moor/database.g.dart | 1 + .../drift_testcases/lib/database/database.g.dart | 2 ++ .../test/saves_after_migration_regression_test.g.dart | 2 ++ extras/integration_tests/web_wasm/lib/src/database.g.dart | 1 + 15 files changed, 34 insertions(+) diff --git a/docs/lib/snippets/modular/drift/example.drift.dart b/docs/lib/snippets/modular/drift/example.drift.dart index 543c6ac3a..ea9703b6a 100644 --- a/docs/lib/snippets/modular/drift/example.drift.dart +++ b/docs/lib/snippets/modular/drift/example.drift.dart @@ -42,6 +42,7 @@ class Todos extends i0.Table with i0.TableInfo { String get aliasedName => _alias ?? 'todos'; @override String get actualTableName => 'todos'; + static String get actualTableNameStatic => 'todos'; @override i0.VerificationContext validateIntegrity(i0.Insertable instance, {bool isInserting = false}) { @@ -283,6 +284,7 @@ class Categories extends i0.Table with i0.TableInfo { String get aliasedName => _alias ?? 'categories'; @override String get actualTableName => 'categories'; + static String get actualTableNameStatic => 'categories'; @override i0.VerificationContext validateIntegrity(i0.Insertable instance, {bool isInserting = false}) { diff --git a/drift/example/main.g.dart b/drift/example/main.g.dart index 574838c97..db2563ed5 100644 --- a/drift/example/main.g.dart +++ b/drift/example/main.g.dart @@ -29,6 +29,7 @@ class $TodoCategoriesTable extends TodoCategories String get aliasedName => _alias ?? 'todo_categories'; @override String get actualTableName => 'todo_categories'; + static String get actualTableNameStatic => 'todo_categories'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -228,6 +229,7 @@ class $TodoItemsTable extends TodoItems String get aliasedName => _alias ?? 'todo_items'; @override String get actualTableName => 'todo_items'; + static String get actualTableNameStatic => 'todo_items'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { diff --git a/drift/test/generated/custom_tables.g.dart b/drift/test/generated/custom_tables.g.dart index b9b041d79..ae8990667 100644 --- a/drift/test/generated/custom_tables.g.dart +++ b/drift/test/generated/custom_tables.g.dart @@ -21,6 +21,7 @@ class NoIds extends Table with TableInfo { String get aliasedName => _alias ?? 'no_ids'; @override String get actualTableName => 'no_ids'; + static String get actualTableNameStatic => 'no_ids'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -121,6 +122,7 @@ class WithDefaults extends Table with TableInfo { String get aliasedName => _alias ?? 'with_defaults'; @override String get actualTableName => 'with_defaults'; + static String get actualTableNameStatic => 'with_defaults'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -317,6 +319,7 @@ class WithConstraints extends Table String get aliasedName => _alias ?? 'with_constraints'; @override String get actualTableName => 'with_constraints'; + static String get actualTableNameStatic => 'with_constraints'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -560,6 +563,7 @@ class ConfigTable extends Table with TableInfo { String get aliasedName => _alias ?? 'config'; @override String get actualTableName => 'config'; + static String get actualTableNameStatic => 'config'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -858,6 +862,7 @@ class Mytable extends Table with TableInfo { String get aliasedName => _alias ?? 'mytable'; @override String get actualTableName => 'mytable'; + static String get actualTableNameStatic => 'mytable'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -1120,6 +1125,7 @@ class Email extends Table String get aliasedName => _alias ?? 'email'; @override String get actualTableName => 'email'; + static String get actualTableNameStatic => 'email'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -1344,6 +1350,7 @@ class WeirdTable extends Table with TableInfo { String get aliasedName => _alias ?? 'Expression'; @override String get actualTableName => 'Expression'; + static String get actualTableNameStatic => 'Expression'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { diff --git a/drift/test/generated/todos.g.dart b/drift/test/generated/todos.g.dart index 63d2eec14..d1a85fe7f 100644 --- a/drift/test/generated/todos.g.dart +++ b/drift/test/generated/todos.g.dart @@ -50,6 +50,7 @@ class $CategoriesTable extends Categories String get aliasedName => _alias ?? 'categories'; @override String get actualTableName => 'categories'; + static String get actualTableNameStatic => 'categories'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -321,6 +322,7 @@ class $TodosTableTable extends TodosTable String get aliasedName => _alias ?? 'todos'; @override String get actualTableName => 'todos'; + static String get actualTableNameStatic => 'todos'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -670,6 +672,7 @@ class $UsersTable extends Users with TableInfo<$UsersTable, User> { String get aliasedName => _alias ?? 'users'; @override String get actualTableName => 'users'; + static String get actualTableNameStatic => 'users'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -938,6 +941,7 @@ class $SharedTodosTable extends SharedTodos String get aliasedName => _alias ?? 'shared_todos'; @override String get actualTableName => 'shared_todos'; + static String get actualTableNameStatic => 'shared_todos'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -1142,6 +1146,7 @@ class $TableWithoutPKTable extends TableWithoutPK String get aliasedName => _alias ?? 'table_without_p_k'; @override String get actualTableName => 'table_without_p_k'; + static String get actualTableNameStatic => 'table_without_p_k'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -1323,6 +1328,7 @@ class $PureDefaultsTable extends PureDefaults String get aliasedName => _alias ?? 'pure_defaults'; @override String get actualTableName => 'pure_defaults'; + static String get actualTableNameStatic => 'pure_defaults'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { diff --git a/drift/test/integration_tests/regress_2166_test.g.dart b/drift/test/integration_tests/regress_2166_test.g.dart index ee4ddfccf..0f1159fb3 100644 --- a/drift/test/integration_tests/regress_2166_test.g.dart +++ b/drift/test/integration_tests/regress_2166_test.g.dart @@ -29,6 +29,7 @@ class $_SomeTableTable extends _SomeTable String get aliasedName => _alias ?? 'some_table'; @override String get actualTableName => 'some_table'; + static String get actualTableNameStatic => 'some_table'; @override VerificationContext validateIntegrity(Insertable<_SomeTableData> instance, {bool isInserting = false}) { diff --git a/examples/migrations_example/lib/database.g.dart b/examples/migrations_example/lib/database.g.dart index 03050074e..6bb6b8d35 100644 --- a/examples/migrations_example/lib/database.g.dart +++ b/examples/migrations_example/lib/database.g.dart @@ -45,6 +45,7 @@ class $UsersTable extends Users with TableInfo<$UsersTable, User> { String get aliasedName => _alias ?? 'users'; @override String get actualTableName => 'users'; + static String get actualTableNameStatic => 'users'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -295,6 +296,7 @@ class Groups extends Table with TableInfo { String get aliasedName => _alias ?? 'groups'; @override String get actualTableName => 'groups'; + static String get actualTableNameStatic => 'groups'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -545,6 +547,7 @@ class Notes extends Table String get aliasedName => _alias ?? 'notes'; @override String get actualTableName => 'notes'; + static String get actualTableNameStatic => 'notes'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { diff --git a/examples/modular/lib/src/posts.drift.dart b/examples/modular/lib/src/posts.drift.dart index fc98a1f36..997f97348 100644 --- a/examples/modular/lib/src/posts.drift.dart +++ b/examples/modular/lib/src/posts.drift.dart @@ -33,6 +33,7 @@ class Posts extends i0.Table with i0.TableInfo { String get aliasedName => _alias ?? 'posts'; @override String get actualTableName => 'posts'; + static String get actualTableNameStatic => 'posts'; @override i0.VerificationContext validateIntegrity(i0.Insertable instance, {bool isInserting = false}) { @@ -239,6 +240,7 @@ class Likes extends i0.Table with i0.TableInfo { String get aliasedName => _alias ?? 'likes'; @override String get actualTableName => 'likes'; + static String get actualTableNameStatic => 'likes'; @override i0.VerificationContext validateIntegrity(i0.Insertable instance, {bool isInserting = false}) { diff --git a/examples/modular/lib/src/search.drift.dart b/examples/modular/lib/src/search.drift.dart index 67c4641ac..55cccad49 100644 --- a/examples/modular/lib/src/search.drift.dart +++ b/examples/modular/lib/src/search.drift.dart @@ -32,6 +32,7 @@ class SearchInPosts extends i0.Table String get aliasedName => _alias ?? 'search_in_posts'; @override String get actualTableName => 'search_in_posts'; + static String get actualTableNameStatic => 'search_in_posts'; @override i0.VerificationContext validateIntegrity( i0.Insertable instance, diff --git a/examples/modular/lib/src/users.drift.dart b/examples/modular/lib/src/users.drift.dart index bbde099b5..4441c9ffb 100644 --- a/examples/modular/lib/src/users.drift.dart +++ b/examples/modular/lib/src/users.drift.dart @@ -51,6 +51,7 @@ class Users extends i0.Table with i0.TableInfo { String get aliasedName => _alias ?? 'users'; @override String get actualTableName => 'users'; + static String get actualTableNameStatic => 'users'; @override i0.VerificationContext validateIntegrity(i0.Insertable instance, {bool isInserting = false}) { @@ -341,6 +342,7 @@ class Follows extends i0.Table with i0.TableInfo { String get aliasedName => _alias ?? 'follows'; @override String get actualTableName => 'follows'; + static String get actualTableNameStatic => 'follows'; @override i0.VerificationContext validateIntegrity(i0.Insertable instance, {bool isInserting = false}) { diff --git a/examples/web_worker_example/lib/database.g.dart b/examples/web_worker_example/lib/database.g.dart index 9a2367e8b..519b9d0ef 100644 --- a/examples/web_worker_example/lib/database.g.dart +++ b/examples/web_worker_example/lib/database.g.dart @@ -26,6 +26,7 @@ class Entries extends Table with TableInfo { String get aliasedName => _alias ?? 'entries'; @override String get actualTableName => 'entries'; + static String get actualTableNameStatic => 'entries'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { diff --git a/examples/with_built_value/lib/database.drift.dart b/examples/with_built_value/lib/database.drift.dart index 36719b40f..36bf85121 100644 --- a/examples/with_built_value/lib/database.drift.dart +++ b/examples/with_built_value/lib/database.drift.dart @@ -25,6 +25,7 @@ class Users extends Table with TableInfo { String get aliasedName => _alias ?? 'users'; @override String get actualTableName => 'users'; + static String get actualTableNameStatic => 'users'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { diff --git a/extras/benchmarks/lib/src/moor/database.g.dart b/extras/benchmarks/lib/src/moor/database.g.dart index 00214196c..73363eafe 100644 --- a/extras/benchmarks/lib/src/moor/database.g.dart +++ b/extras/benchmarks/lib/src/moor/database.g.dart @@ -25,6 +25,7 @@ class $KeyValuesTable extends KeyValues String get aliasedName => _alias ?? 'key_values'; @override String get actualTableName => 'key_values'; + static String get actualTableNameStatic => 'key_values'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { diff --git a/extras/integration_tests/drift_testcases/lib/database/database.g.dart b/extras/integration_tests/drift_testcases/lib/database/database.g.dart index d3fdba9a8..1f40c0040 100644 --- a/extras/integration_tests/drift_testcases/lib/database/database.g.dart +++ b/extras/integration_tests/drift_testcases/lib/database/database.g.dart @@ -51,6 +51,7 @@ class $UsersTable extends Users with TableInfo<$UsersTable, User> { String get aliasedName => _alias ?? 'users'; @override String get actualTableName => 'users'; + static String get actualTableNameStatic => 'users'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -350,6 +351,7 @@ class $FriendshipsTable extends Friendships String get aliasedName => _alias ?? 'friendships'; @override String get actualTableName => 'friendships'; + static String get actualTableNameStatic => 'friendships'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { diff --git a/extras/integration_tests/legacy_web/test/saves_after_migration_regression_test.g.dart b/extras/integration_tests/legacy_web/test/saves_after_migration_regression_test.g.dart index 655ba0fe2..6a9d95eef 100644 --- a/extras/integration_tests/legacy_web/test/saves_after_migration_regression_test.g.dart +++ b/extras/integration_tests/legacy_web/test/saves_after_migration_regression_test.g.dart @@ -23,6 +23,7 @@ class $FoosTable extends Foos with TableInfo<$FoosTable, Foo> { String get aliasedName => _alias ?? 'foos'; @override String get actualTableName => 'foos'; + static String get actualTableNameStatic => 'foos'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -160,6 +161,7 @@ class $BarsTable extends Bars with TableInfo<$BarsTable, Bar> { String get aliasedName => _alias ?? 'bars'; @override String get actualTableName => 'bars'; + static String get actualTableNameStatic => 'bars'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { diff --git a/extras/integration_tests/web_wasm/lib/src/database.g.dart b/extras/integration_tests/web_wasm/lib/src/database.g.dart index 9abedd16c..92c2b2b45 100644 --- a/extras/integration_tests/web_wasm/lib/src/database.g.dart +++ b/extras/integration_tests/web_wasm/lib/src/database.g.dart @@ -30,6 +30,7 @@ class $TestTableTable extends TestTable String get aliasedName => _alias ?? 'test_table'; @override String get actualTableName => 'test_table'; + static String get actualTableNameStatic => 'test_table'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { From 5b6571ec7fa36a73fa5742faaa33e9d59589fb61 Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Wed, 20 Sep 2023 21:59:31 +0800 Subject: [PATCH 3/7] doc: Update the changelogs --- drift_dev/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drift_dev/CHANGELOG.md b/drift_dev/CHANGELOG.md index 08c676b59..12dd759c0 100644 --- a/drift_dev/CHANGELOG.md +++ b/drift_dev/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.12.0-dev + +- Adds the static getter `actualTableNameStatic` to generated table classes. + ## 2.11.2 - Follow `export` directives when looking for table imports. From d001ad533f91b990e13f3fd10a4c948a26b4f221 Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Thu, 21 Sep 2023 11:36:10 +0800 Subject: [PATCH 4/7] revamp: Rename actualTableNameStatic into $name --- drift_dev/lib/src/writer/tables/table_writer.dart | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drift_dev/lib/src/writer/tables/table_writer.dart b/drift_dev/lib/src/writer/tables/table_writer.dart index b8bb82157..40466b154 100644 --- a/drift_dev/lib/src/writer/tables/table_writer.dart +++ b/drift_dev/lib/src/writer/tables/table_writer.dart @@ -407,11 +407,9 @@ class TableWriter extends TableOrViewWriter { writeGetColumnsOverride(); buffer ..write('@override\nString get aliasedName => ' - '_alias ?? \'${table.id.name}\';\n') - ..write( - '@override\n String get actualTableName => \'${table.id.name}\';\n') - ..write( - 'static String get actualTableNameStatic => \'${table.id.name}\';\n'); + '_alias ?? actualTableName;\n') + ..write('@override\n String get actualTableName => \$name;\n') + ..write('static const String \$name = \'${table.id.name}\';\n'); _writeValidityCheckMethod(); _writePrimaryKeyOverride(); From 4041eec6d53fd7bcb6f5af7a326c9308367ac646 Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Thu, 21 Sep 2023 11:36:39 +0800 Subject: [PATCH 5/7] chore: Re-run build runner --- .../snippets/modular/drift/example.drift.dart | 12 +++--- drift/example/main.g.dart | 12 +++--- drift/test/generated/custom_tables.g.dart | 42 +++++++++---------- drift/test/generated/todos.g.dart | 36 ++++++++-------- .../regress_2166_test.g.dart | 6 +-- .../migrations_example/lib/database.g.dart | 18 ++++---- examples/modular/lib/src/posts.drift.dart | 12 +++--- examples/modular/lib/src/search.drift.dart | 6 +-- examples/modular/lib/src/users.drift.dart | 12 +++--- .../web_worker_example/lib/database.g.dart | 6 +-- .../with_built_value/lib/database.drift.dart | 6 +-- .../benchmarks/lib/src/moor/database.g.dart | 6 +-- .../lib/database/database.g.dart | 12 +++--- ...ves_after_migration_regression_test.g.dart | 12 +++--- .../web_wasm/lib/src/database.g.dart | 6 +-- 15 files changed, 102 insertions(+), 102 deletions(-) diff --git a/docs/lib/snippets/modular/drift/example.drift.dart b/docs/lib/snippets/modular/drift/example.drift.dart index ea9703b6a..1cf7c677c 100644 --- a/docs/lib/snippets/modular/drift/example.drift.dart +++ b/docs/lib/snippets/modular/drift/example.drift.dart @@ -39,10 +39,10 @@ class Todos extends i0.Table with i0.TableInfo { @override List get $columns => [id, title, content, category]; @override - String get aliasedName => _alias ?? 'todos'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'todos'; - static String get actualTableNameStatic => 'todos'; + String get actualTableName => $name; + static const String $name = 'todos'; @override i0.VerificationContext validateIntegrity(i0.Insertable instance, {bool isInserting = false}) { @@ -281,10 +281,10 @@ class Categories extends i0.Table with i0.TableInfo { @override List get $columns => [id, description]; @override - String get aliasedName => _alias ?? 'categories'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'categories'; - static String get actualTableNameStatic => 'categories'; + String get actualTableName => $name; + static const String $name = 'categories'; @override i0.VerificationContext validateIntegrity(i0.Insertable instance, {bool isInserting = false}) { diff --git a/drift/example/main.g.dart b/drift/example/main.g.dart index db2563ed5..adb70e1bf 100644 --- a/drift/example/main.g.dart +++ b/drift/example/main.g.dart @@ -26,10 +26,10 @@ class $TodoCategoriesTable extends TodoCategories @override List get $columns => [id, name]; @override - String get aliasedName => _alias ?? 'todo_categories'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'todo_categories'; - static String get actualTableNameStatic => 'todo_categories'; + String get actualTableName => $name; + static const String $name = 'todo_categories'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -226,10 +226,10 @@ class $TodoItemsTable extends TodoItems List get $columns => [id, title, content, categoryId, generatedText]; @override - String get aliasedName => _alias ?? 'todo_items'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'todo_items'; - static String get actualTableNameStatic => 'todo_items'; + String get actualTableName => $name; + static const String $name = 'todo_items'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { diff --git a/drift/test/generated/custom_tables.g.dart b/drift/test/generated/custom_tables.g.dart index ae8990667..7f02afa85 100644 --- a/drift/test/generated/custom_tables.g.dart +++ b/drift/test/generated/custom_tables.g.dart @@ -18,10 +18,10 @@ class NoIds extends Table with TableInfo { @override List get $columns => [payload]; @override - String get aliasedName => _alias ?? 'no_ids'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'no_ids'; - static String get actualTableNameStatic => 'no_ids'; + String get actualTableName => $name; + static const String $name = 'no_ids'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -119,10 +119,10 @@ class WithDefaults extends Table with TableInfo { @override List get $columns => [a, b]; @override - String get aliasedName => _alias ?? 'with_defaults'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'with_defaults'; - static String get actualTableNameStatic => 'with_defaults'; + String get actualTableName => $name; + static const String $name = 'with_defaults'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -316,10 +316,10 @@ class WithConstraints extends Table @override List get $columns => [a, b, c]; @override - String get aliasedName => _alias ?? 'with_constraints'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'with_constraints'; - static String get actualTableNameStatic => 'with_constraints'; + String get actualTableName => $name; + static const String $name = 'with_constraints'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -560,10 +560,10 @@ class ConfigTable extends Table with TableInfo { List get $columns => [configKey, configValue, syncState, syncStateImplicit]; @override - String get aliasedName => _alias ?? 'config'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'config'; - static String get actualTableNameStatic => 'config'; + String get actualTableName => $name; + static const String $name = 'config'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -859,10 +859,10 @@ class Mytable extends Table with TableInfo { List get $columns => [someid, sometext, isInserting, somedate]; @override - String get aliasedName => _alias ?? 'mytable'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'mytable'; - static String get actualTableNameStatic => 'mytable'; + String get actualTableName => $name; + static const String $name = 'mytable'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -1122,10 +1122,10 @@ class Email extends Table @override List get $columns => [sender, title, body]; @override - String get aliasedName => _alias ?? 'email'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'email'; - static String get actualTableNameStatic => 'email'; + String get actualTableName => $name; + static const String $name = 'email'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -1347,10 +1347,10 @@ class WeirdTable extends Table with TableInfo { @override List get $columns => [sqlClass, textColumn]; @override - String get aliasedName => _alias ?? 'Expression'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'Expression'; - static String get actualTableNameStatic => 'Expression'; + String get actualTableName => $name; + static const String $name = 'Expression'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { diff --git a/drift/test/generated/todos.g.dart b/drift/test/generated/todos.g.dart index d1a85fe7f..6362fc833 100644 --- a/drift/test/generated/todos.g.dart +++ b/drift/test/generated/todos.g.dart @@ -47,10 +47,10 @@ class $CategoriesTable extends Categories List get $columns => [id, description, priority, descriptionInUpperCase]; @override - String get aliasedName => _alias ?? 'categories'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'categories'; - static String get actualTableNameStatic => 'categories'; + String get actualTableName => $name; + static const String $name = 'categories'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -319,10 +319,10 @@ class $TodosTableTable extends TodosTable List get $columns => [id, title, content, targetDate, category, status]; @override - String get aliasedName => _alias ?? 'todos'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'todos'; - static String get actualTableNameStatic => 'todos'; + String get actualTableName => $name; + static const String $name = 'todos'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -669,10 +669,10 @@ class $UsersTable extends Users with TableInfo<$UsersTable, User> { List get $columns => [id, name, isAwesome, profilePicture, creationTime]; @override - String get aliasedName => _alias ?? 'users'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'users'; - static String get actualTableNameStatic => 'users'; + String get actualTableName => $name; + static const String $name = 'users'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -938,10 +938,10 @@ class $SharedTodosTable extends SharedTodos @override List get $columns => [todo, user]; @override - String get aliasedName => _alias ?? 'shared_todos'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'shared_todos'; - static String get actualTableNameStatic => 'shared_todos'; + String get actualTableName => $name; + static const String $name = 'shared_todos'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -1143,10 +1143,10 @@ class $TableWithoutPKTable extends TableWithoutPK List get $columns => [notReallyAnId, someFloat, webSafeInt, custom]; @override - String get aliasedName => _alias ?? 'table_without_p_k'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'table_without_p_k'; - static String get actualTableNameStatic => 'table_without_p_k'; + String get actualTableName => $name; + static const String $name = 'table_without_p_k'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -1325,10 +1325,10 @@ class $PureDefaultsTable extends PureDefaults @override List get $columns => [txt]; @override - String get aliasedName => _alias ?? 'pure_defaults'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'pure_defaults'; - static String get actualTableNameStatic => 'pure_defaults'; + String get actualTableName => $name; + static const String $name = 'pure_defaults'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { diff --git a/drift/test/integration_tests/regress_2166_test.g.dart b/drift/test/integration_tests/regress_2166_test.g.dart index 0f1159fb3..6f16c66d9 100644 --- a/drift/test/integration_tests/regress_2166_test.g.dart +++ b/drift/test/integration_tests/regress_2166_test.g.dart @@ -26,10 +26,10 @@ class $_SomeTableTable extends _SomeTable @override List get $columns => [id, name]; @override - String get aliasedName => _alias ?? 'some_table'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'some_table'; - static String get actualTableNameStatic => 'some_table'; + String get actualTableName => $name; + static const String $name = 'some_table'; @override VerificationContext validateIntegrity(Insertable<_SomeTableData> instance, {bool isInserting = false}) { diff --git a/examples/migrations_example/lib/database.g.dart b/examples/migrations_example/lib/database.g.dart index 6bb6b8d35..f06569554 100644 --- a/examples/migrations_example/lib/database.g.dart +++ b/examples/migrations_example/lib/database.g.dart @@ -42,10 +42,10 @@ class $UsersTable extends Users with TableInfo<$UsersTable, User> { @override List get $columns => [id, name, birthday, nextUser]; @override - String get aliasedName => _alias ?? 'users'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'users'; - static String get actualTableNameStatic => 'users'; + String get actualTableName => $name; + static const String $name = 'users'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -293,10 +293,10 @@ class Groups extends Table with TableInfo { @override List get $columns => [id, title, deleted, owner]; @override - String get aliasedName => _alias ?? 'groups'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'groups'; - static String get actualTableNameStatic => 'groups'; + String get actualTableName => $name; + static const String $name = 'groups'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -544,10 +544,10 @@ class Notes extends Table @override List get $columns => [title, content, searchTerms]; @override - String get aliasedName => _alias ?? 'notes'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'notes'; - static String get actualTableNameStatic => 'notes'; + String get actualTableName => $name; + static const String $name = 'notes'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { diff --git a/examples/modular/lib/src/posts.drift.dart b/examples/modular/lib/src/posts.drift.dart index 997f97348..24bea9b9f 100644 --- a/examples/modular/lib/src/posts.drift.dart +++ b/examples/modular/lib/src/posts.drift.dart @@ -30,10 +30,10 @@ class Posts extends i0.Table with i0.TableInfo { @override List get $columns => [id, author, content]; @override - String get aliasedName => _alias ?? 'posts'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'posts'; - static String get actualTableNameStatic => 'posts'; + String get actualTableName => $name; + static const String $name = 'posts'; @override i0.VerificationContext validateIntegrity(i0.Insertable instance, {bool isInserting = false}) { @@ -237,10 +237,10 @@ class Likes extends i0.Table with i0.TableInfo { @override List get $columns => [post, likedBy]; @override - String get aliasedName => _alias ?? 'likes'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'likes'; - static String get actualTableNameStatic => 'likes'; + String get actualTableName => $name; + static const String $name = 'likes'; @override i0.VerificationContext validateIntegrity(i0.Insertable instance, {bool isInserting = false}) { diff --git a/examples/modular/lib/src/search.drift.dart b/examples/modular/lib/src/search.drift.dart index 55cccad49..35949ae87 100644 --- a/examples/modular/lib/src/search.drift.dart +++ b/examples/modular/lib/src/search.drift.dart @@ -29,10 +29,10 @@ class SearchInPosts extends i0.Table @override List get $columns => [author, content]; @override - String get aliasedName => _alias ?? 'search_in_posts'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'search_in_posts'; - static String get actualTableNameStatic => 'search_in_posts'; + String get actualTableName => $name; + static const String $name = 'search_in_posts'; @override i0.VerificationContext validateIntegrity( i0.Insertable instance, diff --git a/examples/modular/lib/src/users.drift.dart b/examples/modular/lib/src/users.drift.dart index 4441c9ffb..a21531134 100644 --- a/examples/modular/lib/src/users.drift.dart +++ b/examples/modular/lib/src/users.drift.dart @@ -48,10 +48,10 @@ class Users extends i0.Table with i0.TableInfo { List get $columns => [id, name, biography, preferences, profilePicture]; @override - String get aliasedName => _alias ?? 'users'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'users'; - static String get actualTableNameStatic => 'users'; + String get actualTableName => $name; + static const String $name = 'users'; @override i0.VerificationContext validateIntegrity(i0.Insertable instance, {bool isInserting = false}) { @@ -339,10 +339,10 @@ class Follows extends i0.Table with i0.TableInfo { @override List get $columns => [followed, follower]; @override - String get aliasedName => _alias ?? 'follows'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'follows'; - static String get actualTableNameStatic => 'follows'; + String get actualTableName => $name; + static const String $name = 'follows'; @override i0.VerificationContext validateIntegrity(i0.Insertable instance, {bool isInserting = false}) { diff --git a/examples/web_worker_example/lib/database.g.dart b/examples/web_worker_example/lib/database.g.dart index 519b9d0ef..ca90faf15 100644 --- a/examples/web_worker_example/lib/database.g.dart +++ b/examples/web_worker_example/lib/database.g.dart @@ -23,10 +23,10 @@ class Entries extends Table with TableInfo { @override List get $columns => [id, value]; @override - String get aliasedName => _alias ?? 'entries'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'entries'; - static String get actualTableNameStatic => 'entries'; + String get actualTableName => $name; + static const String $name = 'entries'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { diff --git a/examples/with_built_value/lib/database.drift.dart b/examples/with_built_value/lib/database.drift.dart index 36bf85121..f90d28dbe 100644 --- a/examples/with_built_value/lib/database.drift.dart +++ b/examples/with_built_value/lib/database.drift.dart @@ -22,10 +22,10 @@ class Users extends Table with TableInfo { @override List get $columns => [id, name]; @override - String get aliasedName => _alias ?? 'users'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'users'; - static String get actualTableNameStatic => 'users'; + String get actualTableName => $name; + static const String $name = 'users'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { diff --git a/extras/benchmarks/lib/src/moor/database.g.dart b/extras/benchmarks/lib/src/moor/database.g.dart index 73363eafe..a2350074b 100644 --- a/extras/benchmarks/lib/src/moor/database.g.dart +++ b/extras/benchmarks/lib/src/moor/database.g.dart @@ -22,10 +22,10 @@ class $KeyValuesTable extends KeyValues @override List get $columns => [key, value]; @override - String get aliasedName => _alias ?? 'key_values'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'key_values'; - static String get actualTableNameStatic => 'key_values'; + String get actualTableName => $name; + static const String $name = 'key_values'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { diff --git a/extras/integration_tests/drift_testcases/lib/database/database.g.dart b/extras/integration_tests/drift_testcases/lib/database/database.g.dart index 1f40c0040..44742d05f 100644 --- a/extras/integration_tests/drift_testcases/lib/database/database.g.dart +++ b/extras/integration_tests/drift_testcases/lib/database/database.g.dart @@ -48,10 +48,10 @@ class $UsersTable extends Users with TableInfo<$UsersTable, User> { List get $columns => [id, name, birthDate, profilePicture, preferences]; @override - String get aliasedName => _alias ?? 'users'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'users'; - static String get actualTableNameStatic => 'users'; + String get actualTableName => $name; + static const String $name = 'users'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -348,10 +348,10 @@ class $FriendshipsTable extends Friendships List get $columns => [firstUser, secondUser, reallyGoodFriends]; @override - String get aliasedName => _alias ?? 'friendships'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'friendships'; - static String get actualTableNameStatic => 'friendships'; + String get actualTableName => $name; + static const String $name = 'friendships'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { diff --git a/extras/integration_tests/legacy_web/test/saves_after_migration_regression_test.g.dart b/extras/integration_tests/legacy_web/test/saves_after_migration_regression_test.g.dart index 6a9d95eef..faf64e61f 100644 --- a/extras/integration_tests/legacy_web/test/saves_after_migration_regression_test.g.dart +++ b/extras/integration_tests/legacy_web/test/saves_after_migration_regression_test.g.dart @@ -20,10 +20,10 @@ class $FoosTable extends Foos with TableInfo<$FoosTable, Foo> { @override List get $columns => [id]; @override - String get aliasedName => _alias ?? 'foos'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'foos'; - static String get actualTableNameStatic => 'foos'; + String get actualTableName => $name; + static const String $name = 'foos'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { @@ -158,10 +158,10 @@ class $BarsTable extends Bars with TableInfo<$BarsTable, Bar> { @override List get $columns => [id]; @override - String get aliasedName => _alias ?? 'bars'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'bars'; - static String get actualTableNameStatic => 'bars'; + String get actualTableName => $name; + static const String $name = 'bars'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { diff --git a/extras/integration_tests/web_wasm/lib/src/database.g.dart b/extras/integration_tests/web_wasm/lib/src/database.g.dart index 92c2b2b45..23b155c08 100644 --- a/extras/integration_tests/web_wasm/lib/src/database.g.dart +++ b/extras/integration_tests/web_wasm/lib/src/database.g.dart @@ -27,10 +27,10 @@ class $TestTableTable extends TestTable @override List get $columns => [id, content]; @override - String get aliasedName => _alias ?? 'test_table'; + String get aliasedName => _alias ?? actualTableName; @override - String get actualTableName => 'test_table'; - static String get actualTableNameStatic => 'test_table'; + String get actualTableName => $name; + static const String $name = 'test_table'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { From 22b0a8fe3618bbb44d4180bd0ac52a27578acf9a Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Thu, 21 Sep 2023 11:36:53 +0800 Subject: [PATCH 6/7] doc: Update changelog --- drift_dev/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift_dev/CHANGELOG.md b/drift_dev/CHANGELOG.md index 12dd759c0..cbff146a5 100644 --- a/drift_dev/CHANGELOG.md +++ b/drift_dev/CHANGELOG.md @@ -1,6 +1,6 @@ ## 2.12.0-dev -- Adds the static getter `actualTableNameStatic` to generated table classes. +- Adds the static getter `$name` to generated table classes. ## 2.11.2 From aa2613c42dd716c20ddf47f59714fc7ad4d9b810 Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Thu, 21 Sep 2023 11:37:07 +0800 Subject: [PATCH 7/7] test: Add a test using .$name --- drift/test/database/tables_test.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drift/test/database/tables_test.dart b/drift/test/database/tables_test.dart index 084a30a59..21426964e 100644 --- a/drift/test/database/tables_test.dart +++ b/drift/test/database/tables_test.dart @@ -67,4 +67,7 @@ void main() { ), ); }); + test('Table classes expose the name of the sql table', () { + expect($TodosTableTable.$name, 'todos'); + }); }