@syntropix/database 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1199 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +620 -0
- package/dist/index.d.ts +620 -9
- package/dist/index.js +1129 -10
- package/dist/index.js.map +1 -0
- package/package.json +8 -4
- package/dist/core/client.d.ts +0 -9
- package/dist/core/client.js +0 -34
- package/dist/core/config.d.ts +0 -7
- package/dist/core/config.js +0 -24
- package/dist/core/dataClient.d.ts +0 -13
- package/dist/core/dataClient.js +0 -71
- package/dist/core/syntropix.d.ts +0 -11
- package/dist/core/syntropix.js +0 -23
- package/dist/core/tableClient.d.ts +0 -16
- package/dist/core/tableClient.js +0 -64
- package/dist/types/basemodel.d.ts +0 -72
- package/dist/types/basemodel.js +0 -416
- package/dist/types/common.d.ts +0 -75
- package/dist/types/common.js +0 -17
- package/dist/types/data-type.d.ts +0 -49
- package/dist/types/data-type.js +0 -19
- package/dist/types/dto/base.d.ts +0 -4
- package/dist/types/dto/base.js +0 -1
- package/dist/types/dto/table.d.ts +0 -22
- package/dist/types/dto/table.js +0 -1
- package/dist/types/field.d.ts +0 -174
- package/dist/types/field.js +0 -123
- package/dist/types/filter.d.ts +0 -82
- package/dist/types/filter.js +0 -224
- package/dist/types/requests.d.ts +0 -83
- package/dist/types/requests.js +0 -6
package/dist/types/basemodel.js
DELETED
|
@@ -1,416 +0,0 @@
|
|
|
1
|
-
// BaseModel implementation with decorator support
|
|
2
|
-
import 'reflect-metadata';
|
|
3
|
-
import { ClientConfig } from '../core/config';
|
|
4
|
-
import { SyntropixClient } from '../core/syntropix';
|
|
5
|
-
import { AggregateFunction } from './common';
|
|
6
|
-
import { ColumnType } from './data-type';
|
|
7
|
-
import { Field, ForeignKeyField, IntegerField } from './field';
|
|
8
|
-
import { AND, EQ, GTE, OR, Value } from './filter';
|
|
9
|
-
// Metadata keys
|
|
10
|
-
const FIELDS_KEY = Symbol('fields');
|
|
11
|
-
const TABLE_NAME_KEY = Symbol('tableName');
|
|
12
|
-
const DESCRIPTION_KEY = Symbol('description');
|
|
13
|
-
const INDEXES_KEY = Symbol('indexes');
|
|
14
|
-
// Column decorator
|
|
15
|
-
export function Column(options = {}) {
|
|
16
|
-
return function (target, propertyKey) {
|
|
17
|
-
const fields = Reflect.getMetadata(FIELDS_KEY, target.constructor) || {};
|
|
18
|
-
const fieldName = options.name || propertyKey.toLowerCase();
|
|
19
|
-
const columnType = options.type || ColumnType.Text;
|
|
20
|
-
const field = new (class extends Field {
|
|
21
|
-
constructor() {
|
|
22
|
-
super(columnType, {
|
|
23
|
-
name: fieldName,
|
|
24
|
-
description: options.description,
|
|
25
|
-
isPrimaryKey: options.primary,
|
|
26
|
-
isNullable: options.nullable,
|
|
27
|
-
autoIncrement: options.autoIncrement,
|
|
28
|
-
default: options.default,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
})();
|
|
32
|
-
fields[propertyKey] = field;
|
|
33
|
-
Reflect.defineMetadata(FIELDS_KEY, fields, target.constructor);
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
// Description decorator
|
|
37
|
-
export function Description(description) {
|
|
38
|
-
return function (target) {
|
|
39
|
-
Reflect.defineMetadata(DESCRIPTION_KEY, description, target);
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
// ForeignKey decorator
|
|
43
|
-
export function ForeignKey(tableName, columnName, options = {}) {
|
|
44
|
-
return function (target, propertyKey) {
|
|
45
|
-
const fields = Reflect.getMetadata(FIELDS_KEY, target.constructor) || {};
|
|
46
|
-
const field = new ForeignKeyField(options.type || ColumnType.Integer, tableName, columnName, {
|
|
47
|
-
onDelete: options.onDelete,
|
|
48
|
-
onUpdate: options.onUpdate,
|
|
49
|
-
description: options.description,
|
|
50
|
-
isNullable: options.nullable,
|
|
51
|
-
default: options.default,
|
|
52
|
-
});
|
|
53
|
-
field.name = options.name || propertyKey.toLowerCase();
|
|
54
|
-
fields[propertyKey] = field;
|
|
55
|
-
Reflect.defineMetadata(FIELDS_KEY, fields, target.constructor);
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
export class BaseModel {
|
|
59
|
-
_client;
|
|
60
|
-
_extra = {};
|
|
61
|
-
constructor(data = {}) {
|
|
62
|
-
const fields = this.getFields();
|
|
63
|
-
// Create a mapping from column names to property names
|
|
64
|
-
const columnToPropertyMap = {};
|
|
65
|
-
for (const [propertyName, field] of Object.entries(fields)) {
|
|
66
|
-
columnToPropertyMap[field.name] = propertyName;
|
|
67
|
-
}
|
|
68
|
-
for (const [key, value] of Object.entries(data)) {
|
|
69
|
-
// Check if key is a property name
|
|
70
|
-
if (key in fields) {
|
|
71
|
-
this[key] = value;
|
|
72
|
-
}
|
|
73
|
-
// Check if key is a column name
|
|
74
|
-
else if (key in columnToPropertyMap) {
|
|
75
|
-
this[columnToPropertyMap[key]] = value;
|
|
76
|
-
}
|
|
77
|
-
// Otherwise, store in _extra
|
|
78
|
-
else {
|
|
79
|
-
this._extra[key] = value;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
// Static metadata getters
|
|
84
|
-
static getTableName() {
|
|
85
|
-
const tableName = Reflect.getMetadata(TABLE_NAME_KEY, this);
|
|
86
|
-
if (tableName)
|
|
87
|
-
return tableName;
|
|
88
|
-
// Check for static tableName property
|
|
89
|
-
if ('tableName' in this && typeof this.tableName === 'string') {
|
|
90
|
-
return this.tableName;
|
|
91
|
-
}
|
|
92
|
-
return this.name.toLowerCase();
|
|
93
|
-
}
|
|
94
|
-
static getDescription() {
|
|
95
|
-
const metadataDescription = Reflect.getMetadata(DESCRIPTION_KEY, this);
|
|
96
|
-
if (metadataDescription)
|
|
97
|
-
return metadataDescription;
|
|
98
|
-
// Check for static description property as fallback
|
|
99
|
-
if ('description' in this && typeof this.description === 'string') {
|
|
100
|
-
return this.description;
|
|
101
|
-
}
|
|
102
|
-
return '';
|
|
103
|
-
}
|
|
104
|
-
static getIndexes() {
|
|
105
|
-
return Reflect.getMetadata(INDEXES_KEY, this) || [];
|
|
106
|
-
}
|
|
107
|
-
static getFields() {
|
|
108
|
-
const fields = Reflect.getMetadata(FIELDS_KEY, this) || {};
|
|
109
|
-
// Check if there's a primary key
|
|
110
|
-
let hasPrimaryKey = false;
|
|
111
|
-
for (const field of Object.values(fields)) {
|
|
112
|
-
if (field.isPrimaryKey) {
|
|
113
|
-
hasPrimaryKey = true;
|
|
114
|
-
field.isNullable = false;
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
// If no primary key, add default 'id' field
|
|
119
|
-
if (!hasPrimaryKey && !('id' in fields)) {
|
|
120
|
-
fields['id'] = new IntegerField({
|
|
121
|
-
isPrimaryKey: true,
|
|
122
|
-
isNullable: false,
|
|
123
|
-
autoIncrement: true,
|
|
124
|
-
description: 'Primary key',
|
|
125
|
-
});
|
|
126
|
-
fields['id'].name = 'id';
|
|
127
|
-
}
|
|
128
|
-
return fields;
|
|
129
|
-
}
|
|
130
|
-
static getPrimaryKeyName() {
|
|
131
|
-
const fields = this.getFields();
|
|
132
|
-
for (const [key, field] of Object.entries(fields)) {
|
|
133
|
-
if (field.isPrimaryKey) {
|
|
134
|
-
return field.name;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return 'id';
|
|
138
|
-
}
|
|
139
|
-
static getAssociations() {
|
|
140
|
-
const fields = this.getFields();
|
|
141
|
-
return Object.values(fields).filter((f) => f instanceof ForeignKeyField);
|
|
142
|
-
}
|
|
143
|
-
// Instance metadata getters
|
|
144
|
-
getFields() {
|
|
145
|
-
return this.constructor.getFields();
|
|
146
|
-
}
|
|
147
|
-
getTableName() {
|
|
148
|
-
return this.constructor.getTableName();
|
|
149
|
-
}
|
|
150
|
-
getPrimaryKeyName() {
|
|
151
|
-
return this.constructor.getPrimaryKeyName();
|
|
152
|
-
}
|
|
153
|
-
getPrimaryKey() {
|
|
154
|
-
const fields = this.getFields();
|
|
155
|
-
for (const field of Object.values(fields)) {
|
|
156
|
-
if (field.isPrimaryKey) {
|
|
157
|
-
return field;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return undefined;
|
|
161
|
-
}
|
|
162
|
-
// Client getter
|
|
163
|
-
get client() {
|
|
164
|
-
if (!this._client) {
|
|
165
|
-
this._client = new SyntropixClient(new ClientConfig());
|
|
166
|
-
}
|
|
167
|
-
return this._client;
|
|
168
|
-
}
|
|
169
|
-
// Table operations
|
|
170
|
-
static async createTable(_client) {
|
|
171
|
-
const fields = this.getFields();
|
|
172
|
-
const columns = Object.values(fields).map((f) => f.into());
|
|
173
|
-
const foreignKeys = this.getAssociations().map((f) => ({
|
|
174
|
-
fromTable: this.getTableName(),
|
|
175
|
-
fromColumn: f.name,
|
|
176
|
-
toTable: f.tableName,
|
|
177
|
-
toColumn: f.columnName,
|
|
178
|
-
onDelete: f.onDelete,
|
|
179
|
-
onUpdate: f.onUpdate,
|
|
180
|
-
}));
|
|
181
|
-
const indexes = this.getIndexes();
|
|
182
|
-
const client = _client || new SyntropixClient(new ClientConfig());
|
|
183
|
-
return client.table.createTable({
|
|
184
|
-
name: this.getTableName(),
|
|
185
|
-
description: this.getDescription() || 'No description',
|
|
186
|
-
columns,
|
|
187
|
-
foreignKeys: foreignKeys,
|
|
188
|
-
indexes,
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
static async dropTable(_client) {
|
|
192
|
-
const client = _client || new SyntropixClient(new ClientConfig());
|
|
193
|
-
return client.table.dropTable({ name: this.getTableName() });
|
|
194
|
-
}
|
|
195
|
-
static async renameTable(newName, _client) {
|
|
196
|
-
const client = _client || new SyntropixClient(new ClientConfig());
|
|
197
|
-
return client.table.renameTable({
|
|
198
|
-
name: this.getTableName(),
|
|
199
|
-
newName: newName,
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
static async truncateTable(_client) {
|
|
203
|
-
const client = _client || new SyntropixClient(new ClientConfig());
|
|
204
|
-
return client.table.truncateTable({ name: this.getTableName() });
|
|
205
|
-
}
|
|
206
|
-
// Data operations
|
|
207
|
-
static async create(data, _client) {
|
|
208
|
-
const model = this;
|
|
209
|
-
const fields = model.getFields();
|
|
210
|
-
const columns = [];
|
|
211
|
-
const values = [];
|
|
212
|
-
for (const [key, value] of Object.entries(data)) {
|
|
213
|
-
if (key in fields) {
|
|
214
|
-
columns.push(fields[key].name);
|
|
215
|
-
values.push(value);
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
throw new Error(`Invalid field: ${key}`);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
const client = _client || new SyntropixClient(new ClientConfig());
|
|
222
|
-
return client.data.insertOne({
|
|
223
|
-
tableName: model.getTableName(),
|
|
224
|
-
data: {
|
|
225
|
-
columns,
|
|
226
|
-
values: [values],
|
|
227
|
-
},
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
async save(_client) {
|
|
231
|
-
const pk = this.getPrimaryKey();
|
|
232
|
-
const pkValue = this[this.getPrimaryKeyName()];
|
|
233
|
-
const fields = this.getFields();
|
|
234
|
-
if (pkValue === null || pkValue === undefined) {
|
|
235
|
-
const data = {};
|
|
236
|
-
for (const [key, field] of Object.entries(fields)) {
|
|
237
|
-
data[key] = this[key];
|
|
238
|
-
}
|
|
239
|
-
return this.constructor.create(data, _client);
|
|
240
|
-
}
|
|
241
|
-
const columns = [];
|
|
242
|
-
const values = [];
|
|
243
|
-
for (const [key, field] of Object.entries(fields)) {
|
|
244
|
-
if (field.name !== pk?.name) {
|
|
245
|
-
columns.push(field.name);
|
|
246
|
-
values.push(this[key]);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
return (_client ||
|
|
250
|
-
this.client.data.updateByPrimaryKey(pkValue, {
|
|
251
|
-
tableName: this.getTableName(),
|
|
252
|
-
payload: {
|
|
253
|
-
filter: [[]],
|
|
254
|
-
columns,
|
|
255
|
-
values,
|
|
256
|
-
},
|
|
257
|
-
}));
|
|
258
|
-
}
|
|
259
|
-
async remove(filter, _client) {
|
|
260
|
-
const pk = this.getPrimaryKey();
|
|
261
|
-
const pkValue = this[this.getPrimaryKeyName()];
|
|
262
|
-
const finalFilter = filter || OR(AND(EQ(pk?.name || 'id', pkValue)));
|
|
263
|
-
return (_client ||
|
|
264
|
-
this.client.data.deleteData({
|
|
265
|
-
tableName: this.getTableName(),
|
|
266
|
-
payload: {
|
|
267
|
-
filter: finalFilter,
|
|
268
|
-
},
|
|
269
|
-
}));
|
|
270
|
-
}
|
|
271
|
-
static async bulkCreate(datas, batchSize = 32, _client) {
|
|
272
|
-
if (!datas.length)
|
|
273
|
-
return 0;
|
|
274
|
-
if (batchSize <= 0)
|
|
275
|
-
throw new Error('Batch size must be greater than 0');
|
|
276
|
-
const model = this;
|
|
277
|
-
const fields = model.getFields();
|
|
278
|
-
let cnt = 0;
|
|
279
|
-
batchSize = Math.min(batchSize, 128);
|
|
280
|
-
const columns = Object.keys(datas[0]);
|
|
281
|
-
const columnsSet = new Set(columns);
|
|
282
|
-
for (const col of columns) {
|
|
283
|
-
if (!(col in fields)) {
|
|
284
|
-
throw new Error(`Invalid field: ${col}`);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
let values = [];
|
|
288
|
-
const client = _client || new SyntropixClient(new ClientConfig());
|
|
289
|
-
for (const data of datas) {
|
|
290
|
-
if (columnsSet.size !== new Set(Object.keys(data)).size || !columns.every((c) => c in data)) {
|
|
291
|
-
throw new Error('All data must have the same columns');
|
|
292
|
-
}
|
|
293
|
-
values.push(columns.map((c) => data[c]));
|
|
294
|
-
if (values.length === batchSize) {
|
|
295
|
-
cnt += await client.data.insertData({
|
|
296
|
-
tableName: model.getTableName(),
|
|
297
|
-
data: { columns: columns.map((c) => fields[c].name), values },
|
|
298
|
-
});
|
|
299
|
-
values = [];
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
if (values.length > 0) {
|
|
303
|
-
cnt += await client.data.insertData({
|
|
304
|
-
tableName: model.getTableName(),
|
|
305
|
-
data: { columns: columns.map((c) => fields[c].name), values },
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
return cnt;
|
|
309
|
-
}
|
|
310
|
-
static async update(filter, data, _client) {
|
|
311
|
-
const model = this;
|
|
312
|
-
const fields = model.getFields();
|
|
313
|
-
const columns = Object.keys(data);
|
|
314
|
-
if (!columns.length) {
|
|
315
|
-
throw new Error('No columns to update');
|
|
316
|
-
}
|
|
317
|
-
for (const col of columns) {
|
|
318
|
-
if (!(col in fields)) {
|
|
319
|
-
throw new Error(`Invalid field: ${col}`);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
const values = columns.map((c) => data[c]);
|
|
323
|
-
const client = _client || new SyntropixClient(new ClientConfig());
|
|
324
|
-
return client.data.updateData({
|
|
325
|
-
tableName: model.getTableName(),
|
|
326
|
-
payload: {
|
|
327
|
-
filter,
|
|
328
|
-
columns: columns.map((c) => fields[c].name),
|
|
329
|
-
values,
|
|
330
|
-
},
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
static async delete(filter, _client) {
|
|
334
|
-
const model = this;
|
|
335
|
-
const client = _client || new SyntropixClient(new ClientConfig());
|
|
336
|
-
return client.data.deleteData({
|
|
337
|
-
tableName: model.getTableName(),
|
|
338
|
-
payload: { filter },
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
static async get(filter, select, _client) {
|
|
342
|
-
const model = this;
|
|
343
|
-
const fields = model.getFields();
|
|
344
|
-
const client = _client || new SyntropixClient(new ClientConfig());
|
|
345
|
-
const data = await client.data.queryOne({
|
|
346
|
-
tableName: model.getTableName(),
|
|
347
|
-
query: {
|
|
348
|
-
filter,
|
|
349
|
-
select: select || Object.values(fields).map((f) => f.name),
|
|
350
|
-
limit: 1,
|
|
351
|
-
},
|
|
352
|
-
});
|
|
353
|
-
return new this(data);
|
|
354
|
-
}
|
|
355
|
-
static async filter(options) {
|
|
356
|
-
const model = this;
|
|
357
|
-
const client = options._client || new SyntropixClient(new ClientConfig());
|
|
358
|
-
const data = await client.data.queryMany({
|
|
359
|
-
tableName: model.getTableName(),
|
|
360
|
-
query: {
|
|
361
|
-
filter: options.filter,
|
|
362
|
-
sort: options.sort,
|
|
363
|
-
aggregate: options.aggregate,
|
|
364
|
-
join: options.join ? [options.join] : undefined,
|
|
365
|
-
limit: options.limit,
|
|
366
|
-
offset: options.offset,
|
|
367
|
-
groupBy: options.groupBy,
|
|
368
|
-
select: options.select,
|
|
369
|
-
},
|
|
370
|
-
});
|
|
371
|
-
return data.map((item) => new this(item));
|
|
372
|
-
}
|
|
373
|
-
static async count(options = {}) {
|
|
374
|
-
const model = this;
|
|
375
|
-
const client = options._client || new SyntropixClient(new ClientConfig());
|
|
376
|
-
const data = await client.data.queryMany({
|
|
377
|
-
tableName: model.getTableName(),
|
|
378
|
-
query: {
|
|
379
|
-
filter: options.filter || [[GTE('id', Value(0))]],
|
|
380
|
-
aggregate: [
|
|
381
|
-
{
|
|
382
|
-
column: 'id',
|
|
383
|
-
function: AggregateFunction.Count,
|
|
384
|
-
alias: 'count',
|
|
385
|
-
},
|
|
386
|
-
],
|
|
387
|
-
join: options.join ? [options.join] : undefined,
|
|
388
|
-
limit: 1,
|
|
389
|
-
offset: 0,
|
|
390
|
-
groupBy: options.groupBy,
|
|
391
|
-
select: ['count'],
|
|
392
|
-
},
|
|
393
|
-
});
|
|
394
|
-
return data.length > 0 ? data[0].count : 0;
|
|
395
|
-
}
|
|
396
|
-
toString() {
|
|
397
|
-
const fields = this.getFields();
|
|
398
|
-
const data = {};
|
|
399
|
-
for (const key of Object.keys(fields)) {
|
|
400
|
-
const value = this[key];
|
|
401
|
-
if (!(value instanceof Field)) {
|
|
402
|
-
data[key] = value;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
data._extra = this._extra;
|
|
406
|
-
return `${this.constructor.name}(${JSON.stringify(data).slice(1, -1)})`;
|
|
407
|
-
}
|
|
408
|
-
toJSON() {
|
|
409
|
-
const fields = this.getFields();
|
|
410
|
-
const data = {};
|
|
411
|
-
for (const key of Object.keys(fields)) {
|
|
412
|
-
data[key] = this[key];
|
|
413
|
-
}
|
|
414
|
-
return { ...data, ...this._extra };
|
|
415
|
-
}
|
|
416
|
-
}
|
package/dist/types/common.d.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { SortType } from './filter';
|
|
2
|
-
import { SyntropixDBAccessType } from './requests';
|
|
3
|
-
export declare enum ForeignKeyAction {
|
|
4
|
-
Cascade = "Cascade",
|
|
5
|
-
Restrict = "Restrict",
|
|
6
|
-
SetNull = "SetNull",
|
|
7
|
-
NoAction = "NoAction",
|
|
8
|
-
SetDefault = "SetDefault"
|
|
9
|
-
}
|
|
10
|
-
export declare enum AggregateFunction {
|
|
11
|
-
Count = "Count",
|
|
12
|
-
Sum = "Sum",
|
|
13
|
-
Avg = "Avg",
|
|
14
|
-
Min = "Min",
|
|
15
|
-
Max = "Max",
|
|
16
|
-
CountDistinct = "CountDistinct"
|
|
17
|
-
}
|
|
18
|
-
export interface Sort {
|
|
19
|
-
column: string;
|
|
20
|
-
direction: SortType;
|
|
21
|
-
}
|
|
22
|
-
export interface Join {
|
|
23
|
-
table: string;
|
|
24
|
-
on: any;
|
|
25
|
-
}
|
|
26
|
-
export interface Aggregate {
|
|
27
|
-
column: string;
|
|
28
|
-
function: AggregateFunction;
|
|
29
|
-
alias: string;
|
|
30
|
-
}
|
|
31
|
-
export interface GroupBy {
|
|
32
|
-
columns: string[];
|
|
33
|
-
}
|
|
34
|
-
export interface ForeignKey {
|
|
35
|
-
name?: string;
|
|
36
|
-
fromTable: string;
|
|
37
|
-
fromColumn: string;
|
|
38
|
-
toTable: string;
|
|
39
|
-
toColumn: string;
|
|
40
|
-
onDelete?: ForeignKeyAction;
|
|
41
|
-
onUpdate?: ForeignKeyAction;
|
|
42
|
-
}
|
|
43
|
-
export interface Column {
|
|
44
|
-
name: string;
|
|
45
|
-
columnType: string | Record<string, any>;
|
|
46
|
-
description?: string;
|
|
47
|
-
isPrimaryKey?: boolean;
|
|
48
|
-
isNullable?: boolean;
|
|
49
|
-
autoIncrement?: boolean;
|
|
50
|
-
default?: any;
|
|
51
|
-
defaultAccess?: SyntropixDBAccessType;
|
|
52
|
-
}
|
|
53
|
-
export interface Index {
|
|
54
|
-
name: string;
|
|
55
|
-
columns: string[];
|
|
56
|
-
unique?: boolean;
|
|
57
|
-
}
|
|
58
|
-
export interface SyntropixDBColumn {
|
|
59
|
-
id: string;
|
|
60
|
-
name: string;
|
|
61
|
-
description: string;
|
|
62
|
-
columnType: string | Record<string, any>;
|
|
63
|
-
isNullable: boolean;
|
|
64
|
-
isPrimaryKey: boolean;
|
|
65
|
-
autoIncrement: boolean;
|
|
66
|
-
default?: any;
|
|
67
|
-
defaultAccess?: SyntropixDBAccessType;
|
|
68
|
-
}
|
|
69
|
-
export interface SyntropixDBTable {
|
|
70
|
-
id: string;
|
|
71
|
-
name: string;
|
|
72
|
-
description: string;
|
|
73
|
-
createdAt: Date;
|
|
74
|
-
columns: SyntropixDBColumn[];
|
|
75
|
-
}
|
package/dist/types/common.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export var ForeignKeyAction;
|
|
2
|
-
(function (ForeignKeyAction) {
|
|
3
|
-
ForeignKeyAction["Cascade"] = "Cascade";
|
|
4
|
-
ForeignKeyAction["Restrict"] = "Restrict";
|
|
5
|
-
ForeignKeyAction["SetNull"] = "SetNull";
|
|
6
|
-
ForeignKeyAction["NoAction"] = "NoAction";
|
|
7
|
-
ForeignKeyAction["SetDefault"] = "SetDefault";
|
|
8
|
-
})(ForeignKeyAction || (ForeignKeyAction = {}));
|
|
9
|
-
export var AggregateFunction;
|
|
10
|
-
(function (AggregateFunction) {
|
|
11
|
-
AggregateFunction["Count"] = "Count";
|
|
12
|
-
AggregateFunction["Sum"] = "Sum";
|
|
13
|
-
AggregateFunction["Avg"] = "Avg";
|
|
14
|
-
AggregateFunction["Min"] = "Min";
|
|
15
|
-
AggregateFunction["Max"] = "Max";
|
|
16
|
-
AggregateFunction["CountDistinct"] = "CountDistinct";
|
|
17
|
-
})(AggregateFunction || (AggregateFunction = {}));
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
interface StringType {
|
|
2
|
-
type: 'String';
|
|
3
|
-
maxLength: number;
|
|
4
|
-
}
|
|
5
|
-
interface VectorType {
|
|
6
|
-
type: 'Vector';
|
|
7
|
-
dimensions: number;
|
|
8
|
-
}
|
|
9
|
-
interface ArrayType {
|
|
10
|
-
type: 'Array';
|
|
11
|
-
dataType: string | Record<string, any>;
|
|
12
|
-
}
|
|
13
|
-
interface EnumType {
|
|
14
|
-
type: 'Enum';
|
|
15
|
-
name: string;
|
|
16
|
-
variants: string[];
|
|
17
|
-
}
|
|
18
|
-
interface MoneyType {
|
|
19
|
-
type: 'Money';
|
|
20
|
-
precision: number;
|
|
21
|
-
scale: number;
|
|
22
|
-
}
|
|
23
|
-
interface DecimalType {
|
|
24
|
-
type: 'Decimal';
|
|
25
|
-
precision: number;
|
|
26
|
-
scale: number;
|
|
27
|
-
}
|
|
28
|
-
export declare const ColumnType: {
|
|
29
|
-
readonly Integer: "Integer";
|
|
30
|
-
readonly String: (maxLength: number) => StringType;
|
|
31
|
-
readonly Text: "Text";
|
|
32
|
-
readonly Boolean: "Boolean";
|
|
33
|
-
readonly DateTime: "DateTime";
|
|
34
|
-
readonly Timestamp: "Timestamp";
|
|
35
|
-
readonly Date: "Date";
|
|
36
|
-
readonly Json: "Json";
|
|
37
|
-
readonly Uuid: "Uuid";
|
|
38
|
-
readonly Double: "Double";
|
|
39
|
-
readonly Vector: (dimensions: number) => VectorType;
|
|
40
|
-
readonly Array: (dataType: string | Record<string, any>) => ArrayType;
|
|
41
|
-
readonly Enum: (name: string, variants: string[]) => EnumType;
|
|
42
|
-
readonly Money: (precision: number, scale: number) => MoneyType;
|
|
43
|
-
readonly Decimal: (precision: number, scale: number) => DecimalType;
|
|
44
|
-
};
|
|
45
|
-
type DataTypeMap = typeof ColumnType;
|
|
46
|
-
type DataTypeValues = DataTypeMap[keyof DataTypeMap];
|
|
47
|
-
type DataTypeReturnTypes = ReturnType<Extract<DataTypeValues, (...args: any[]) => any>>;
|
|
48
|
-
export type ColumnType = Exclude<DataTypeValues, (...args: any[]) => any> | DataTypeReturnTypes;
|
|
49
|
-
export {};
|
package/dist/types/data-type.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export const ColumnType = {
|
|
2
|
-
// Basic types
|
|
3
|
-
Integer: 'Integer',
|
|
4
|
-
String: (maxLength) => ({ type: 'String', maxLength }),
|
|
5
|
-
Text: 'Text',
|
|
6
|
-
Boolean: 'Boolean',
|
|
7
|
-
DateTime: 'DateTime',
|
|
8
|
-
Timestamp: 'Timestamp',
|
|
9
|
-
Date: 'Date',
|
|
10
|
-
Json: 'Json',
|
|
11
|
-
Uuid: 'Uuid',
|
|
12
|
-
Double: 'Double',
|
|
13
|
-
// Complex types
|
|
14
|
-
Vector: (dimensions) => ({ type: 'Vector', dimensions }),
|
|
15
|
-
Array: (dataType) => ({ type: 'Array', dataType }),
|
|
16
|
-
Enum: (name, variants) => ({ type: 'Enum', name, variants }),
|
|
17
|
-
Money: (precision, scale) => ({ type: 'Money', precision, scale }),
|
|
18
|
-
Decimal: (precision, scale) => ({ type: 'Decimal', precision, scale }),
|
|
19
|
-
};
|
package/dist/types/dto/base.d.ts
DELETED
package/dist/types/dto/base.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Column, ForeignKey, Index } from '../common';
|
|
2
|
-
export interface TableCreateResponse {
|
|
3
|
-
_id: {
|
|
4
|
-
$oid: string;
|
|
5
|
-
};
|
|
6
|
-
table: {
|
|
7
|
-
id: string;
|
|
8
|
-
name: string;
|
|
9
|
-
description: string;
|
|
10
|
-
createdAt: any;
|
|
11
|
-
columns: Column[];
|
|
12
|
-
foreignKeys: ForeignKey[];
|
|
13
|
-
indexes: Index[];
|
|
14
|
-
schema: string;
|
|
15
|
-
defaultAccess: string | null;
|
|
16
|
-
};
|
|
17
|
-
createdAt: any;
|
|
18
|
-
updatedAt: any;
|
|
19
|
-
createdBy: string;
|
|
20
|
-
metadata: Record<string, any>;
|
|
21
|
-
triggers: any[];
|
|
22
|
-
}
|
package/dist/types/dto/table.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|