toPgSqlFragment method
Implementation
String toPgSqlFragment() {
String type;
switch (columnType) {
case ColumnType.bigint:
type = 'bigint';
break;
case ColumnType.boolean:
type = 'boolean';
break;
case ColumnType.bytea:
type = 'bytea';
break;
case ColumnType.doublePrecision:
type = 'double precision';
break;
case ColumnType.integer:
type = 'integer';
break;
case ColumnType.json:
type = 'json';
break;
case ColumnType.jsonb:
type = 'jsonb';
break;
case ColumnType.text:
type = 'text';
break;
case ColumnType.timestampWithoutTimeZone:
type = 'timestamp without time zone';
break;
case ColumnType.uuid:
type = 'uuid';
break;
case ColumnType.vector:
type = 'vector(${vectorDimension!})';
break;
case ColumnType.halfvec:
type = 'halfvec(${vectorDimension!})';
break;
case ColumnType.sparsevec:
type = 'sparsevec(${vectorDimension!})';
break;
case ColumnType.bit:
type = 'bit(${vectorDimension!})';
break;
case ColumnType.geography:
type = 'geography(Point,${Geography.defaultSrid})';
break;
case ColumnType.geographyLineString:
type = 'geography(LineString,${Geography.defaultSrid})';
break;
case ColumnType.geographyPolygon:
type = 'geography(Polygon,${Geography.defaultSrid})';
break;
case ColumnType.geographyGeometryCollection:
type = 'geography(GeometryCollection,${Geography.defaultSrid})';
break;
case ColumnType.unknown:
throw (const FormatException('Unknown column type'));
}
var nullable = isNullable ? '' : ' NOT NULL';
var defaultSql = columnType.getPgColumnDefault(columnDefault);
var defaultValue = defaultSql != null ? ' DEFAULT $defaultSql' : '';
if (isIntSerialColumn) {
type = columnType == ColumnType.bigint || isPrimary
? 'bigserial'
: 'serial';
defaultValue = '';
nullable = ' NOT NULL';
}
// The id column is special.
if (isPrimary) {
if (isNullable) {
throw const FormatException('The id column must be non-nullable');
}
type = '$type PRIMARY KEY';
nullable = '';
}
return '"$name" $type$nullable$defaultValue';
}