mirror of https://github.com/AMT-Cheif/drift.git
Write column getter into schema file (#1739)
This commit is contained in:
parent
5def49b1fa
commit
b25921a362
|
@ -97,6 +97,7 @@ class SchemaWriter {
|
|||
Map _columnData(MoorColumn column) {
|
||||
return {
|
||||
'name': column.name.name,
|
||||
'getter_name': column.dartGetterName,
|
||||
'moor_type': column.type.toString(),
|
||||
'nullable': column.nullable,
|
||||
'customConstraints': column.customConstraints,
|
||||
|
@ -286,12 +287,13 @@ class SchemaReader {
|
|||
for (final feature in data['dsl_features'] as List<dynamic>)
|
||||
_columnFeature(feature)
|
||||
];
|
||||
final getterName = data['getter_name'] as String?;
|
||||
|
||||
// Note: Not including client default code because that usually depends on
|
||||
// imports from the database.
|
||||
return MoorColumn(
|
||||
name: ColumnName.explicitly(name),
|
||||
dartGetterName: ReCase(name).camelCase,
|
||||
dartGetterName: getterName ?? ReCase(name).camelCase,
|
||||
type: moorType,
|
||||
nullable: nullable,
|
||||
defaultArgument: data['default_dart'] as String?,
|
||||
|
|
|
@ -47,7 +47,7 @@ import 'package:drift/drift.dart';
|
|||
class Users extends Table {
|
||||
IntColumn get id => integer().autoIncrement()();
|
||||
TextColumn get name => text()();
|
||||
TextColumn get settings => text().map(const SettingsConverter())();
|
||||
TextColumn get settings => text().named('setting').map(const SettingsConverter())();
|
||||
}
|
||||
|
||||
class Settings {}
|
||||
|
@ -104,6 +104,7 @@ const expected = r'''
|
|||
"columns":[
|
||||
{
|
||||
"name":"id",
|
||||
"getter_name": "id",
|
||||
"moor_type":"ColumnType.integer",
|
||||
"nullable":false,
|
||||
"customConstraints":"NOT NULL PRIMARY KEY AUTOINCREMENT",
|
||||
|
@ -116,6 +117,7 @@ const expected = r'''
|
|||
},
|
||||
{
|
||||
"name":"name",
|
||||
"getter_name": "name",
|
||||
"moor_type":"ColumnType.text",
|
||||
"nullable":false,
|
||||
"customConstraints":"NOT NULL",
|
||||
|
@ -142,6 +144,7 @@ const expected = r'''
|
|||
"columns":[
|
||||
{
|
||||
"name":"id",
|
||||
"getter_name": "id",
|
||||
"moor_type":"ColumnType.integer",
|
||||
"nullable":false,
|
||||
"customConstraints":null,
|
||||
|
@ -154,6 +157,7 @@ const expected = r'''
|
|||
},
|
||||
{
|
||||
"name":"name",
|
||||
"getter_name": "name",
|
||||
"moor_type":"ColumnType.text",
|
||||
"nullable":false,
|
||||
"customConstraints":null,
|
||||
|
@ -164,7 +168,8 @@ const expected = r'''
|
|||
]
|
||||
},
|
||||
{
|
||||
"name":"settings",
|
||||
"name":"setting",
|
||||
"getter_name": "settings",
|
||||
"moor_type":"ColumnType.text",
|
||||
"nullable":false,
|
||||
"customConstraints":null,
|
||||
|
@ -195,6 +200,7 @@ const expected = r'''
|
|||
"columns":[
|
||||
{
|
||||
"name":"group",
|
||||
"getter_name": "group",
|
||||
"moor_type":"ColumnType.integer",
|
||||
"nullable":false,
|
||||
"customConstraints":"NOT NULL REFERENCES \"groups\"(id)",
|
||||
|
@ -206,6 +212,7 @@ const expected = r'''
|
|||
},
|
||||
{
|
||||
"name":"user",
|
||||
"getter_name": "user",
|
||||
"moor_type":"ColumnType.integer",
|
||||
"nullable":false,
|
||||
"customConstraints":"NOT NULL REFERENCES users(id)",
|
||||
|
@ -217,6 +224,7 @@ const expected = r'''
|
|||
},
|
||||
{
|
||||
"name":"is_admin",
|
||||
"getter_name": "isAdmin",
|
||||
"moor_type":"ColumnType.boolean",
|
||||
"nullable":false,
|
||||
"customConstraints":"NOT NULL DEFAULT FALSE",
|
||||
|
@ -276,6 +284,7 @@ const expected = r'''
|
|||
"columns": [
|
||||
{
|
||||
"name": "sender",
|
||||
"getter_name": "sender",
|
||||
"moor_type": "ColumnType.text",
|
||||
"nullable": false,
|
||||
"customConstraints": "",
|
||||
|
@ -285,6 +294,7 @@ const expected = r'''
|
|||
},
|
||||
{
|
||||
"name": "title",
|
||||
"getter_name": "title",
|
||||
"moor_type": "ColumnType.text",
|
||||
"nullable": false,
|
||||
"customConstraints": "",
|
||||
|
@ -294,6 +304,7 @@ const expected = r'''
|
|||
},
|
||||
{
|
||||
"name": "body",
|
||||
"getter_name": "body",
|
||||
"moor_type": "ColumnType.text",
|
||||
"nullable": false,
|
||||
"customConstraints": "",
|
||||
|
|
Loading…
Reference in New Issue