UNPKG

@gftdcojp/gftd-orm

Version:

Enterprise-grade real-time data platform with ksqlDB, inspired by Supabase architecture

137 lines 4.28 kB
"use strict"; /** * FieldType 定義 - Drizzle ORM ライクな DSL */ Object.defineProperty(exports, "__esModule", { value: true }); exports.FieldType = exports.MapFieldType = exports.ArrayFieldType = exports.DecimalFieldType = exports.TimeFieldType = exports.DateFieldType = exports.TimestampFieldType = exports.UuidFieldType = exports.BooleanFieldType = exports.DoubleFieldType = exports.LongFieldType = exports.IntFieldType = exports.StringFieldType = exports.BaseFieldType = void 0; class BaseFieldType { constructor(type, logicalType) { this.definition = { type, nullable: true, primaryKey: false, logicalType, }; } notNull() { this.definition.nullable = false; return this; } primaryKey() { this.definition.primaryKey = true; this.definition.nullable = false; return this; } withDefault(defaultValue) { this.definition.default = defaultValue; return this; } getDefinition() { return { ...this.definition }; } toAvroType() { const baseType = this.definition.logicalType ? { type: this.definition.type, logicalType: this.definition.logicalType } : this.definition.type; if (this.definition.nullable) { return ['null', baseType]; } return baseType; } } exports.BaseFieldType = BaseFieldType; class StringFieldType extends BaseFieldType { constructor() { super('string'); } } exports.StringFieldType = StringFieldType; class IntFieldType extends BaseFieldType { constructor() { super('int'); } } exports.IntFieldType = IntFieldType; class LongFieldType extends BaseFieldType { constructor() { super('long'); } } exports.LongFieldType = LongFieldType; class DoubleFieldType extends BaseFieldType { constructor() { super('double'); } } exports.DoubleFieldType = DoubleFieldType; class BooleanFieldType extends BaseFieldType { constructor() { super('boolean'); } } exports.BooleanFieldType = BooleanFieldType; class UuidFieldType extends BaseFieldType { constructor() { super('string', 'uuid'); } } exports.UuidFieldType = UuidFieldType; class TimestampFieldType extends BaseFieldType { constructor() { super('long', 'timestamp-millis'); } } exports.TimestampFieldType = TimestampFieldType; class DateFieldType extends BaseFieldType { constructor() { super('int', 'date'); } } exports.DateFieldType = DateFieldType; class TimeFieldType extends BaseFieldType { constructor() { super('int', 'time-millis'); } } exports.TimeFieldType = TimeFieldType; class DecimalFieldType extends BaseFieldType { constructor(precision = 10, scale = 2) { super('bytes', 'decimal'); this.definition.logicalType = 'decimal'; this.definition.precision = precision; this.definition.scale = scale; } } exports.DecimalFieldType = DecimalFieldType; class ArrayFieldType extends BaseFieldType { constructor(itemType) { super('array'); this.definition.items = itemType.toAvroType(); } } exports.ArrayFieldType = ArrayFieldType; class MapFieldType extends BaseFieldType { constructor(valueType) { super('map'); this.definition.values = valueType.toAvroType(); } } exports.MapFieldType = MapFieldType; /** * FieldType エクスポート - 設計案の通り(各フィールドは新しいインスタンスを返す) */ exports.FieldType = { get STRING() { return new StringFieldType(); }, get INT() { return new IntFieldType(); }, get LONG() { return new LongFieldType(); }, get DOUBLE() { return new DoubleFieldType(); }, get BOOLEAN() { return new BooleanFieldType(); }, get UUID() { return new UuidFieldType(); }, get TIMESTAMP() { return new TimestampFieldType(); }, get DATE() { return new DateFieldType(); }, get TIME() { return new TimeFieldType(); }, DECIMAL: (precision, scale) => new DecimalFieldType(precision, scale), ARRAY: (itemType) => new ArrayFieldType(itemType), MAP: (valueType) => new MapFieldType(valueType), }; //# sourceMappingURL=field-types.js.map