Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class SqliteSchemaGenerator {
return SchemaColumn(
column.name!,
column.columnType!,
defaultValue: column.defaultValue,
nullable: column.nullable,
unique: column.unique,
);
Expand All @@ -228,13 +229,15 @@ class SqliteSchemaGenerator {
return SchemaColumn(
column.name!,
Column.fromDartPrimitive(checker.asPrimitive),
defaultValue: column.defaultValue,
nullable: column.nullable,
unique: column.unique,
);
} else if (checker.isEnum) {
return SchemaColumn(
column.name!,
column.enumAsString ? Column.varchar : Column.integer,
defaultValue: column.defaultValue,
nullable: column.nullable,
unique: column.unique,
);
Expand All @@ -256,13 +259,15 @@ class SqliteSchemaGenerator {
return SchemaColumn(
column.name!,
Column.varchar,
defaultValue: column.defaultValue,
nullable: column.nullable,
unique: column.unique,
);
} else if (checker.toJsonMethod != null) {
return SchemaColumn(
column.name!,
Column.varchar,
defaultValue: column.defaultValue,
nullable: column.nullable,
unique: column.unique,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'package:brick_sqlite/brick_sqlite.dart';

const output = '''
// GENERATED CODE DO NOT EDIT
// This file should be version controlled
import 'package:brick_sqlite/db.dart';

/// All intelligently-generated migrations from all `@Migratable` classes on disk
final migrations = <Migration>{};

/// A consumable database structure including the latest generated migration.
final schema = Schema(
0,
generatorVersion: 1,
tables: <SchemaTable>{
SchemaTable(
'DefaultValue',
columns: <SchemaColumn>{
SchemaColumn(
'_brick_id',
Column.integer,
autoincrement: true,
nullable: false,
isPrimaryKey: true,
),
SchemaColumn('name', Column.varchar),
SchemaColumn('version', Column.integer, defaultValue: 1),
},
indices: <SchemaIndex>{},
),
},
);
''';

/// [SqliteSerializable] **does not** produce code.
/// A `const` class is required from an non-relative import,
/// and [SqliteSerializable] was arbitrarily chosen for this test.
/// This will do nothing outside of this exact test suite.
@SqliteSerializable()
class DefaultValue {
final String? name;

@Sqlite(defaultValue: '1')
final int? version;

DefaultValue({this.name, this.version});
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:source_gen/source_gen.dart';
import 'package:test/test.dart';

import 'sqlite_schema/test_all_field_types.dart' as all_field_types;
import 'sqlite_schema/test_default_value.dart' as default_value;
import 'sqlite_schema/test_enum_as_string.dart' as enum_as_string;
import 'sqlite_schema/test_from_to_json.dart' as from_to_json;
import 'sqlite_schema/test_index_annotation.dart' as index_annotation;
Expand Down Expand Up @@ -66,6 +67,11 @@ void main() {
final input = await generateInput('from_to_json');
expect(input, from_to_json.output);
});

test('DefaultValue', () async {
final input = await generateInput('default_value');
expect(input, default_value.output);
});
});

test('#createMigration', () async {
Expand Down
Loading