mirror of https://github.com/AMT-Cheif/drift.git
Revert table declaration class
This commit is contained in:
parent
b5af3edf73
commit
9e443dba2a
|
@ -6,10 +6,59 @@ abstract class HasResultSet {
|
|||
const HasResultSet();
|
||||
}
|
||||
|
||||
/// Base class for dsl [Table]s and [View]s.
|
||||
abstract class ColumnDefinition extends HasResultSet {
|
||||
/// Default constant constructor.
|
||||
const ColumnDefinition();
|
||||
/// Subclasses represent a table in a database generated by drift.
|
||||
abstract class Table extends HasResultSet {
|
||||
/// Defines a table to be used with drift.
|
||||
const Table();
|
||||
|
||||
/// The sql table name to be used. By default, drift will use the snake_case
|
||||
/// representation of your class name as the sql table name. For instance, a
|
||||
/// [Table] class named `LocalSettings` will be called `local_settings` by
|
||||
/// default.
|
||||
/// You can change that behavior by overriding this method to use a custom
|
||||
/// name. Please note that you must directly return a string literal by using
|
||||
/// a getter. For instance `@override String get tableName => 'my_table';` is
|
||||
/// valid, whereas `@override final String tableName = 'my_table';` or
|
||||
/// `@override String get tableName => createMyTableName();` is not.
|
||||
@visibleForOverriding
|
||||
String? get tableName => null;
|
||||
|
||||
/// Whether to append a `WITHOUT ROWID` clause in the `CREATE TABLE`
|
||||
/// statement. This is intended to be used by generated code only.
|
||||
bool get withoutRowId => false;
|
||||
|
||||
/// Drift will write some table constraints automatically, for instance when
|
||||
/// you override [primaryKey]. You can turn this behavior off if you want to.
|
||||
/// This is intended to be used by generated code only.
|
||||
bool get dontWriteConstraints => false;
|
||||
|
||||
/// Override this to specify custom primary keys:
|
||||
/// ```dart
|
||||
/// class IngredientInRecipes extends Table {
|
||||
/// @override
|
||||
/// Set<Column> get primaryKey => {recipe, ingredient};
|
||||
///
|
||||
/// IntColumn get recipe => integer()();
|
||||
/// IntColumn get ingredient => integer()();
|
||||
///
|
||||
/// IntColumn get amountInGrams => integer().named('amount')();
|
||||
///}
|
||||
/// ```
|
||||
/// The getter must return a set literal using the `=>` syntax so that the
|
||||
/// drift generator can understand the code.
|
||||
/// Also, please note that it's an error to have an
|
||||
/// [BuildIntColumn.autoIncrement] column and a custom primary key.
|
||||
/// As an auto-incremented `IntColumn` is recognized by drift to be the
|
||||
/// primary key, doing so will result in an exception thrown at runtime.
|
||||
@visibleForOverriding
|
||||
Set<Column>? get primaryKey => null;
|
||||
|
||||
/// Custom table constraints that should be added to the table.
|
||||
///
|
||||
/// See also:
|
||||
/// - https://www.sqlite.org/syntax/table-constraint.html, which defines what
|
||||
/// table constraints are supported.
|
||||
List<String> get customConstraints => [];
|
||||
|
||||
/// Use this as the body of a getter to declare a column that holds integers.
|
||||
/// Example (inside the body of a table class):
|
||||
|
@ -69,63 +118,8 @@ abstract class ColumnDefinition extends HasResultSet {
|
|||
ColumnBuilder<double> real() => _isGenerated();
|
||||
}
|
||||
|
||||
/// Subclasses represent a table in a database generated by drift.
|
||||
abstract class Table extends ColumnDefinition {
|
||||
/// Defines a table to be used with drift.
|
||||
const Table();
|
||||
|
||||
/// The sql table name to be used. By default, drift will use the snake_case
|
||||
/// representation of your class name as the sql table name. For instance, a
|
||||
/// [Table] class named `LocalSettings` will be called `local_settings` by
|
||||
/// default.
|
||||
/// You can change that behavior by overriding this method to use a custom
|
||||
/// name. Please note that you must directly return a string literal by using
|
||||
/// a getter. For instance `@override String get tableName => 'my_table';` is
|
||||
/// valid, whereas `@override final String tableName = 'my_table';` or
|
||||
/// `@override String get tableName => createMyTableName();` is not.
|
||||
@visibleForOverriding
|
||||
String? get tableName => null;
|
||||
|
||||
/// Whether to append a `WITHOUT ROWID` clause in the `CREATE TABLE`
|
||||
/// statement. This is intended to be used by generated code only.
|
||||
bool get withoutRowId => false;
|
||||
|
||||
/// Drift will write some table constraints automatically, for instance when
|
||||
/// you override [primaryKey]. You can turn this behavior off if you want to.
|
||||
/// This is intended to be used by generated code only.
|
||||
bool get dontWriteConstraints => false;
|
||||
|
||||
/// Override this to specify custom primary keys:
|
||||
/// ```dart
|
||||
/// class IngredientInRecipes extends Table {
|
||||
/// @override
|
||||
/// Set<Column> get primaryKey => {recipe, ingredient};
|
||||
///
|
||||
/// IntColumn get recipe => integer()();
|
||||
/// IntColumn get ingredient => integer()();
|
||||
///
|
||||
/// IntColumn get amountInGrams => integer().named('amount')();
|
||||
///}
|
||||
/// ```
|
||||
/// The getter must return a set literal using the `=>` syntax so that the
|
||||
/// drift generator can understand the code.
|
||||
/// Also, please note that it's an error to have an
|
||||
/// [BuildIntColumn.autoIncrement] column and a custom primary key.
|
||||
/// As an auto-incremented `IntColumn` is recognized by drift to be the
|
||||
/// primary key, doing so will result in an exception thrown at runtime.
|
||||
@visibleForOverriding
|
||||
Set<Column>? get primaryKey => null;
|
||||
|
||||
/// Custom table constraints that should be added to the table.
|
||||
///
|
||||
/// See also:
|
||||
/// - https://www.sqlite.org/syntax/table-constraint.html, which defines what
|
||||
/// table constraints are supported.
|
||||
List<String> get customConstraints => [];
|
||||
}
|
||||
|
||||
/// Subclasses represent a view in a database generated by drift.
|
||||
abstract class View extends ColumnDefinition {
|
||||
abstract class View extends HasResultSet {
|
||||
/// Defines a view to be used with drift.
|
||||
const View();
|
||||
|
||||
|
|
Loading…
Reference in New Issue