UNPKG

@gftdcojp/ksqldb-orm

Version:

ksqldb-orm - Server-Side TypeScript ORM for ksqlDB with enterprise security extensions

189 lines 5.43 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; exports.string = string; exports.int = int; exports.long = long; exports.double = double; exports.boolean = boolean; exports.uuid = uuid; exports.timestamp = timestamp; exports.date = date; exports.time = time; exports.decimal = decimal; exports.array = array; exports.map = map; 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), }; /** * 個別のフィールド関数エクスポート(Drizzle ORMライク) * 各関数は新しいフィールドインスタンスを返す */ function string() { return new StringFieldType(); } function int() { return new IntFieldType(); } function long() { return new LongFieldType(); } function double() { return new DoubleFieldType(); } function boolean() { return new BooleanFieldType(); } function uuid() { return new UuidFieldType(); } function timestamp() { return new TimestampFieldType(); } function date() { return new DateFieldType(); } function time() { return new TimeFieldType(); } function decimal(precision, scale) { return new DecimalFieldType(precision, scale); } function array(itemType) { return new ArrayFieldType(itemType); } function map(valueType) { return new MapFieldType(valueType); } //# sourceMappingURL=field-types.js.map