2019-07-04 21:30:21 +00:00
|
|
|
const List<String> SQL_RESERVED_WORDS = [
|
2018-08-24 12:30:38 +00:00
|
|
|
'SELECT',
|
|
|
|
'UPDATE',
|
|
|
|
'INSERT',
|
|
|
|
'DELETE',
|
|
|
|
'FROM',
|
|
|
|
'ASC',
|
|
|
|
'DESC',
|
|
|
|
'VALUES',
|
|
|
|
'RETURNING',
|
|
|
|
'ORDER',
|
|
|
|
'BY',
|
|
|
|
];
|
|
|
|
|
|
|
|
/// Applies additional attributes to a database column.
|
|
|
|
class Column {
|
|
|
|
/// If `true`, a SQL field will be nullable.
|
|
|
|
final bool isNullable;
|
|
|
|
|
|
|
|
/// Specifies the length of a `VARCHAR`.
|
|
|
|
final int length;
|
|
|
|
|
|
|
|
/// Explicitly defines a SQL type for this column.
|
|
|
|
final ColumnType type;
|
|
|
|
|
|
|
|
/// Specifies what kind of index this column is, if any.
|
|
|
|
final IndexType indexType;
|
|
|
|
|
|
|
|
const Column(
|
2019-04-02 23:19:01 +00:00
|
|
|
{this.isNullable = true,
|
2018-08-24 12:30:38 +00:00
|
|
|
this.length,
|
|
|
|
this.type,
|
2019-04-02 23:19:01 +00:00
|
|
|
this.indexType = IndexType.none});
|
2018-08-24 12:30:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class PrimaryKey extends Column {
|
|
|
|
const PrimaryKey({ColumnType columnType})
|
2019-07-04 21:30:42 +00:00
|
|
|
: super(type: columnType, indexType: IndexType.primaryKey);
|
2018-08-24 12:30:38 +00:00
|
|
|
}
|
|
|
|
|
2019-07-04 21:30:21 +00:00
|
|
|
const Column primaryKey = PrimaryKey();
|
2018-08-24 12:30:38 +00:00
|
|
|
|
|
|
|
/// Maps to SQL index types.
|
|
|
|
enum IndexType {
|
|
|
|
none,
|
|
|
|
|
|
|
|
/// Standard index.
|
|
|
|
standardIndex,
|
|
|
|
|
|
|
|
/// A primary key.
|
|
|
|
primaryKey,
|
|
|
|
|
|
|
|
/// A *unique* index.
|
|
|
|
unique
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Maps to SQL data types.
|
|
|
|
///
|
|
|
|
/// Features all types from this list: http://www.tutorialspoint.com/sql/sql-data-types.htm
|
|
|
|
class ColumnType {
|
|
|
|
/// The name of this data type.
|
|
|
|
final String name;
|
|
|
|
|
|
|
|
const ColumnType(this.name);
|
|
|
|
|
2019-07-04 21:30:21 +00:00
|
|
|
static const ColumnType boolean = ColumnType('boolean');
|
2018-08-24 12:30:38 +00:00
|
|
|
|
2019-07-04 21:30:21 +00:00
|
|
|
static const ColumnType smallSerial = ColumnType('smallserial');
|
|
|
|
static const ColumnType serial = ColumnType('serial');
|
|
|
|
static const ColumnType bigSerial = ColumnType('bigserial');
|
2018-08-24 12:30:38 +00:00
|
|
|
|
|
|
|
// Numbers
|
2019-07-04 21:30:21 +00:00
|
|
|
static const ColumnType bigInt = ColumnType('bigint');
|
|
|
|
static const ColumnType int = ColumnType('int');
|
|
|
|
static const ColumnType smallInt = ColumnType('smallint');
|
|
|
|
static const ColumnType tinyInt = ColumnType('tinyint');
|
|
|
|
static const ColumnType bit = ColumnType('bit');
|
|
|
|
static const ColumnType decimal = ColumnType('decimal');
|
|
|
|
static const ColumnType numeric = ColumnType('numeric');
|
|
|
|
static const ColumnType money = ColumnType('money');
|
|
|
|
static const ColumnType smallMoney = ColumnType('smallmoney');
|
|
|
|
static const ColumnType float = ColumnType('float');
|
|
|
|
static const ColumnType real = ColumnType('real');
|
2018-08-24 12:30:38 +00:00
|
|
|
|
|
|
|
// Dates and times
|
2019-07-04 21:30:21 +00:00
|
|
|
static const ColumnType dateTime = ColumnType('datetime');
|
|
|
|
static const ColumnType smallDateTime = ColumnType('smalldatetime');
|
|
|
|
static const ColumnType date = ColumnType('date');
|
|
|
|
static const ColumnType time = ColumnType('time');
|
|
|
|
static const ColumnType timeStamp = ColumnType('timestamp');
|
2018-08-24 12:30:38 +00:00
|
|
|
static const ColumnType timeStampWithTimeZone =
|
2019-07-04 21:30:21 +00:00
|
|
|
ColumnType('timestamp with time zone');
|
2018-08-24 12:30:38 +00:00
|
|
|
|
|
|
|
// Strings
|
2019-07-04 21:30:21 +00:00
|
|
|
static const ColumnType char = ColumnType('char');
|
|
|
|
static const ColumnType varChar = ColumnType('varchar');
|
|
|
|
static const ColumnType varCharMax = ColumnType('varchar(max)');
|
|
|
|
static const ColumnType text = ColumnType('text');
|
2018-08-24 12:30:38 +00:00
|
|
|
|
|
|
|
// Unicode strings
|
2019-07-04 21:30:21 +00:00
|
|
|
static const ColumnType nChar = ColumnType('nchar');
|
|
|
|
static const ColumnType nVarChar = ColumnType('nvarchar');
|
|
|
|
static const ColumnType nVarCharMax = ColumnType('nvarchar(max)');
|
|
|
|
static const ColumnType nText = ColumnType('ntext');
|
2018-08-24 12:30:38 +00:00
|
|
|
|
|
|
|
// Binary
|
2019-07-04 21:30:21 +00:00
|
|
|
static const ColumnType binary = ColumnType('binary');
|
|
|
|
static const ColumnType varBinary = ColumnType('varbinary');
|
|
|
|
static const ColumnType varBinaryMax = ColumnType('varbinary(max)');
|
|
|
|
static const ColumnType image = ColumnType('image');
|
2018-08-24 12:30:38 +00:00
|
|
|
|
2019-01-11 00:25:23 +00:00
|
|
|
// JSON.
|
2019-07-04 21:30:21 +00:00
|
|
|
static const ColumnType json = ColumnType('json');
|
|
|
|
static const ColumnType jsonb = ColumnType('jsonb');
|
2019-01-11 00:25:23 +00:00
|
|
|
|
2018-08-24 12:30:38 +00:00
|
|
|
// Misc.
|
2019-07-04 21:30:21 +00:00
|
|
|
static const ColumnType sqlVariant = ColumnType('sql_variant');
|
|
|
|
static const ColumnType uniqueIdentifier = ColumnType('uniqueidentifier');
|
|
|
|
static const ColumnType xml = ColumnType('xml');
|
|
|
|
static const ColumnType cursor = ColumnType('cursor');
|
|
|
|
static const ColumnType table = ColumnType('table');
|
2018-08-24 12:30:38 +00:00
|
|
|
}
|