@syntropix/database 0.0.4 → 0.0.5

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.
@@ -1,277 +0,0 @@
1
- // Field definitions for ORM
2
- import { Column, ForeignKeyAction } from './common';
3
- import { ColumnType, DataType } from './data-type';
4
-
5
- export abstract class Field {
6
- name: string = '';
7
- description: string = '';
8
- column_type: ColumnType;
9
- is_primary_key: boolean = false;
10
- is_nullable: boolean = false;
11
- auto_increment: boolean = false;
12
- default?: any;
13
-
14
- constructor(
15
- column_type: ColumnType,
16
- options: {
17
- name?: string;
18
- description?: string;
19
- is_primary_key?: boolean;
20
- is_nullable?: boolean;
21
- auto_increment?: boolean;
22
- default?: any;
23
- } = {},
24
- ) {
25
- this.column_type = column_type;
26
- this.name = options.name?.toLowerCase() || '';
27
- this.description = options.description || '';
28
- this.is_primary_key = options.is_primary_key || false;
29
- this.is_nullable = options.is_nullable || false;
30
- this.auto_increment = options.auto_increment || false;
31
- this.default = options.default;
32
- }
33
-
34
- into(): Column {
35
- return {
36
- name: this.name,
37
- column_type: this.column_type,
38
- description: this.description,
39
- is_primary_key: this.is_primary_key,
40
- is_nullable: this.is_nullable,
41
- auto_increment: this.auto_increment,
42
- default: this.default,
43
- };
44
- }
45
- }
46
-
47
- export class ForeignKeyField extends Field {
48
- tableName: string;
49
- columnName: string;
50
- onDelete: ForeignKeyAction;
51
- onUpdate: ForeignKeyAction;
52
-
53
- constructor(
54
- column_type: ColumnType,
55
- tableName: string,
56
- columnName: string,
57
- options: {
58
- onDelete?: ForeignKeyAction;
59
- onUpdate?: ForeignKeyAction;
60
- description?: string;
61
- is_primary_key?: boolean;
62
- is_nullable?: boolean;
63
- default?: any;
64
- } = {},
65
- ) {
66
- super(column_type, options);
67
- this.tableName = tableName;
68
- this.columnName = columnName;
69
- this.onDelete = options.onDelete || ForeignKeyAction.CASCADE;
70
- this.onUpdate = options.onUpdate || ForeignKeyAction.CASCADE;
71
- }
72
- }
73
-
74
- export class StringField extends Field {
75
- constructor(
76
- maxLength: number,
77
- options: {
78
- description?: string;
79
- is_primary_key?: boolean;
80
- is_nullable?: boolean;
81
- default?: string;
82
- } = {},
83
- ) {
84
- super(DataType.String(maxLength), options);
85
- }
86
- }
87
-
88
- export class TextField extends Field {
89
- constructor(
90
- options: {
91
- description?: string;
92
- is_primary_key?: boolean;
93
- is_nullable?: boolean;
94
- default?: string;
95
- } = {},
96
- ) {
97
- super(DataType.Text, options);
98
- }
99
- }
100
-
101
- export class IntegerField extends Field {
102
- constructor(
103
- options: {
104
- description?: string;
105
- is_primary_key?: boolean;
106
- is_nullable?: boolean;
107
- auto_increment?: boolean;
108
- default?: number;
109
- } = {},
110
- ) {
111
- super(DataType.Integer, options);
112
- }
113
- }
114
-
115
- export class BooleanField extends Field {
116
- constructor(
117
- options: {
118
- description?: string;
119
- is_primary_key?: boolean;
120
- is_nullable?: boolean;
121
- default?: boolean;
122
- } = {},
123
- ) {
124
- super(DataType.Boolean, options);
125
- }
126
- }
127
-
128
- export class DateTimeField extends Field {
129
- constructor(
130
- options: {
131
- description?: string;
132
- is_primary_key?: boolean;
133
- is_nullable?: boolean;
134
- default?: Date;
135
- } = {},
136
- ) {
137
- super(DataType.DateTime, options);
138
- }
139
- }
140
-
141
- export class TimestampField extends Field {
142
- constructor(
143
- options: {
144
- description?: string;
145
- is_primary_key?: boolean;
146
- is_nullable?: boolean;
147
- default?: Date;
148
- } = {},
149
- ) {
150
- super(DataType.Timestamp, options);
151
- }
152
- }
153
-
154
- export class DateField extends Field {
155
- constructor(
156
- options: {
157
- description?: string;
158
- is_primary_key?: boolean;
159
- is_nullable?: boolean;
160
- default?: Date;
161
- } = {},
162
- ) {
163
- super(DataType.Date, options);
164
- }
165
- }
166
-
167
- export class JsonField extends Field {
168
- constructor(
169
- options: {
170
- description?: string;
171
- is_primary_key?: boolean;
172
- is_nullable?: boolean;
173
- default?: Record<string, any>;
174
- } = {},
175
- ) {
176
- super(DataType.Json, options);
177
- }
178
- }
179
-
180
- export class UuidField extends Field {
181
- constructor(
182
- options: {
183
- description?: string;
184
- is_primary_key?: boolean;
185
- is_nullable?: boolean;
186
- default?: string;
187
- } = {},
188
- ) {
189
- super(DataType.Uuid, options);
190
- }
191
- }
192
-
193
- export class VectorField extends Field {
194
- constructor(
195
- dimensions: number,
196
- options: {
197
- description?: string;
198
- is_primary_key?: boolean;
199
- is_nullable?: boolean;
200
- default?: number[];
201
- } = {},
202
- ) {
203
- super(DataType.Vector(dimensions), options);
204
- }
205
- }
206
-
207
- export class ArrayField extends Field {
208
- constructor(
209
- dataType: ColumnType,
210
- options: {
211
- description?: string;
212
- is_primary_key?: boolean;
213
- is_nullable?: boolean;
214
- default?: any[];
215
- } = {},
216
- ) {
217
- super(DataType.Array(dataType), options);
218
- }
219
- }
220
-
221
- export class EnumField extends Field {
222
- constructor(
223
- name: string,
224
- variants: string[],
225
- options: {
226
- description?: string;
227
- is_primary_key?: boolean;
228
- is_nullable?: boolean;
229
- default?: string;
230
- } = {},
231
- ) {
232
- super(DataType.Enum(name, variants), options);
233
- }
234
- }
235
-
236
- export class MoneyField extends Field {
237
- constructor(
238
- precision: number,
239
- scale: number,
240
- options: {
241
- description?: string;
242
- is_primary_key?: boolean;
243
- is_nullable?: boolean;
244
- default?: number;
245
- } = {},
246
- ) {
247
- super(DataType.Money(precision, scale), options);
248
- }
249
- }
250
-
251
- export class DecimalField extends Field {
252
- constructor(
253
- precision: number,
254
- scale: number,
255
- options: {
256
- description?: string;
257
- is_primary_key?: boolean;
258
- is_nullable?: boolean;
259
- default?: number;
260
- } = {},
261
- ) {
262
- super(DataType.Decimal(precision, scale), options);
263
- }
264
- }
265
-
266
- export class DoubleField extends Field {
267
- constructor(
268
- options: {
269
- description?: string;
270
- is_primary_key?: boolean;
271
- is_nullable?: boolean;
272
- default?: number;
273
- } = {},
274
- ) {
275
- super(DataType.Double, options);
276
- }
277
- }
@@ -1,281 +0,0 @@
1
- // Filter types for database queries
2
- export enum SortType {
3
- DESCENDING = 'DESCENDING',
4
- ASCENDING = 'ASCENDING',
5
- }
6
-
7
- export interface SimilarityOptions {
8
- threshold: number;
9
- order?: SortType;
10
- alias?: string;
11
- }
12
-
13
- export enum FilterOperation {
14
- LT = 'LT',
15
- LTE = 'LTE',
16
- GT = 'GT',
17
- GTE = 'GTE',
18
- EQ = 'EQ',
19
- NEQ = 'NEQ',
20
- Between = 'Between',
21
- In = 'In',
22
- Contains = 'Contains',
23
- Overlap = 'Overlap',
24
- NotIn = 'NotIn',
25
- Like = 'Like',
26
- NotLike = 'NotLike',
27
- ILike = 'ILike',
28
- NotILike = 'NotILike',
29
- IsNull = 'IsNull',
30
- IsNotNull = 'IsNotNull',
31
- Similarity = 'Similarity',
32
- SimilarityDistance = 'SimilarityDistance',
33
- WordSimilarity = 'WordSimilarity',
34
- WordSimilarityDistance = 'WordSimilarityDistance',
35
- StrictWordSimilarity = 'StrictWordSimilarity',
36
- StrictWordSimilarityDistance = 'StrictWordSimilarityDistance',
37
- EuclideanDistance = 'EuclideanDistance',
38
- NegativeInnerProduct = 'NegativeInnerProduct',
39
- CosineDistance = 'CosineDistance',
40
- }
41
-
42
- export interface SyntropixDBFilterItem {
43
- column: string;
44
- operator: FilterOperation;
45
- static_value?: any;
46
- column_value?: string;
47
- similarity_options?: SimilarityOptions;
48
- }
49
-
50
- export type SyntropixDBFilterGroup = SyntropixDBFilterItem[];
51
-
52
- export type SyntropixDBFilter = SyntropixDBFilterGroup[];
53
-
54
- // Legacy type aliases for backward compatibility
55
- export type FilterCondition = SyntropixDBFilter;
56
- export type Filter = SyntropixDBFilter;
57
-
58
- // Filter builder functions
59
- export const AND = (...conditions: SyntropixDBFilterItem[]): SyntropixDBFilterGroup => conditions;
60
-
61
- export const OR = (...conditions: SyntropixDBFilterGroup[]): SyntropixDBFilter => conditions;
62
-
63
- export const EQ = (field: string, value: any): SyntropixDBFilterItem => ({
64
- column: field,
65
- operator: FilterOperation.EQ,
66
- static_value: value,
67
- });
68
-
69
- export const NE = (field: string, value: any): SyntropixDBFilterItem => ({
70
- column: field,
71
- operator: FilterOperation.NEQ,
72
- static_value: value,
73
- });
74
-
75
- export const GT = (field: string, value: any): SyntropixDBFilterItem => ({
76
- column: field,
77
- operator: FilterOperation.GT,
78
- static_value: value,
79
- });
80
-
81
- export const GTE = (field: string, value: any): SyntropixDBFilterItem => ({
82
- column: field,
83
- operator: FilterOperation.GTE,
84
- static_value: value,
85
- });
86
-
87
- export const LT = (field: string, value: any): SyntropixDBFilterItem => ({
88
- column: field,
89
- operator: FilterOperation.LT,
90
- static_value: value,
91
- });
92
-
93
- export const LTE = (field: string, value: any): SyntropixDBFilterItem => ({
94
- column: field,
95
- operator: FilterOperation.LTE,
96
- static_value: value,
97
- });
98
-
99
- export const IN = (field: string, values: any[]): SyntropixDBFilterItem => ({
100
- column: field,
101
- operator: FilterOperation.In,
102
- static_value: values,
103
- });
104
-
105
- export const CONTAINS = (field: string, value: any): SyntropixDBFilterItem => ({
106
- column: field,
107
- operator: FilterOperation.Contains,
108
- static_value: value,
109
- });
110
-
111
- export const OVERLAP = (field: string, value: any): SyntropixDBFilterItem => ({
112
- column: field,
113
- operator: FilterOperation.Overlap,
114
- static_value: value,
115
- });
116
-
117
- export const I_LIKE = (field: string, pattern: string): SyntropixDBFilterItem => ({
118
- column: field,
119
- operator: FilterOperation.ILike,
120
- static_value: pattern,
121
- });
122
-
123
- export const NOT_I_LIKE = (field: string, pattern: string): SyntropixDBFilterItem => ({
124
- column: field,
125
- operator: FilterOperation.NotILike,
126
- static_value: pattern,
127
- });
128
-
129
- export const NOT_IN = (field: string, values: any[]): SyntropixDBFilterItem => ({
130
- column: field,
131
- operator: FilterOperation.NotIn,
132
- static_value: values,
133
- });
134
-
135
- export const LIKE = (field: string, pattern: string): SyntropixDBFilterItem => ({
136
- column: field,
137
- operator: FilterOperation.Like,
138
- static_value: pattern,
139
- });
140
-
141
- export const NOT_LIKE = (field: string, pattern: string): SyntropixDBFilterItem => ({
142
- column: field,
143
- operator: FilterOperation.NotLike,
144
- static_value: pattern,
145
- });
146
-
147
- export const IS_NULL = (field: string): SyntropixDBFilterItem => ({
148
- column: field,
149
- operator: FilterOperation.IsNull,
150
- });
151
-
152
- export const IS_NOT_NULL = (field: string): SyntropixDBFilterItem => ({
153
- column: field,
154
- operator: FilterOperation.IsNotNull,
155
- });
156
-
157
- export const BETWEEN = (field: string, min: any, max: any): SyntropixDBFilterItem => ({
158
- column: field,
159
- operator: FilterOperation.Between,
160
- static_value: [min, max],
161
- });
162
-
163
- // Column comparison (compare two columns)
164
- export const EQ_COL = (field: string, otherField: string): SyntropixDBFilterItem => ({
165
- column: field,
166
- operator: FilterOperation.EQ,
167
- column_value: otherField,
168
- });
169
-
170
- export const NE_COL = (field: string, otherField: string): SyntropixDBFilterItem => ({
171
- column: field,
172
- operator: FilterOperation.NEQ,
173
- column_value: otherField,
174
- });
175
-
176
- export const GT_COL = (field: string, otherField: string): SyntropixDBFilterItem => ({
177
- column: field,
178
- operator: FilterOperation.GT,
179
- column_value: otherField,
180
- });
181
-
182
- export const GTE_COL = (field: string, otherField: string): SyntropixDBFilterItem => ({
183
- column: field,
184
- operator: FilterOperation.GTE,
185
- column_value: otherField,
186
- });
187
-
188
- export const LT_COL = (field: string, otherField: string): SyntropixDBFilterItem => ({
189
- column: field,
190
- operator: FilterOperation.LT,
191
- column_value: otherField,
192
- });
193
-
194
- export const LTE_COL = (field: string, otherField: string): SyntropixDBFilterItem => ({
195
- column: field,
196
- operator: FilterOperation.LTE,
197
- column_value: otherField,
198
- });
199
-
200
- // Similarity operations
201
- export const SIMILARITY = (field: string, value: any, options: SimilarityOptions): SyntropixDBFilterItem => ({
202
- column: field,
203
- operator: FilterOperation.Similarity,
204
- static_value: value,
205
- similarity_options: options,
206
- });
207
-
208
- export const SIMILARITY_DISTANCE = (field: string, value: any, options: SimilarityOptions): SyntropixDBFilterItem => ({
209
- column: field,
210
- operator: FilterOperation.SimilarityDistance,
211
- static_value: value,
212
- similarity_options: options,
213
- });
214
-
215
- export const WORD_SIMILARITY = (field: string, value: any, options: SimilarityOptions): SyntropixDBFilterItem => ({
216
- column: field,
217
- operator: FilterOperation.WordSimilarity,
218
- static_value: value,
219
- similarity_options: options,
220
- });
221
-
222
- export const WORD_SIMILARITY_DISTANCE = (
223
- field: string,
224
- value: any,
225
- options: SimilarityOptions,
226
- ): SyntropixDBFilterItem => ({
227
- column: field,
228
- operator: FilterOperation.WordSimilarityDistance,
229
- static_value: value,
230
- similarity_options: options,
231
- });
232
-
233
- export const STRICT_WORD_SIMILARITY = (
234
- field: string,
235
- value: any,
236
- options: SimilarityOptions,
237
- ): SyntropixDBFilterItem => ({
238
- column: field,
239
- operator: FilterOperation.StrictWordSimilarity,
240
- static_value: value,
241
- similarity_options: options,
242
- });
243
-
244
- export const STRICT_WORD_SIMILARITY_DISTANCE = (
245
- field: string,
246
- value: any,
247
- options: SimilarityOptions,
248
- ): SyntropixDBFilterItem => ({
249
- column: field,
250
- operator: FilterOperation.StrictWordSimilarityDistance,
251
- static_value: value,
252
- similarity_options: options,
253
- });
254
-
255
- export const EUCLIDEAN_DISTANCE = (field: string, value: any, options: SimilarityOptions): SyntropixDBFilterItem => ({
256
- column: field,
257
- operator: FilterOperation.EuclideanDistance,
258
- static_value: value,
259
- similarity_options: options,
260
- });
261
-
262
- export const NEGATIVE_INNER_PRODUCT = (
263
- field: string,
264
- value: any,
265
- options: SimilarityOptions,
266
- ): SyntropixDBFilterItem => ({
267
- column: field,
268
- operator: FilterOperation.NegativeInnerProduct,
269
- static_value: value,
270
- similarity_options: options,
271
- });
272
-
273
- export const COSINE_DISTANCE = (field: string, value: any, options: SimilarityOptions): SyntropixDBFilterItem => ({
274
- column: field,
275
- operator: FilterOperation.CosineDistance,
276
- static_value: value,
277
- similarity_options: options,
278
- });
279
-
280
- // Helper function for values (backward compatibility)
281
- export const Value = (value: any) => value;
@@ -1,91 +0,0 @@
1
- // Request types for database operations
2
- import { Aggregate, Column, ForeignKey, GroupBy, Index, Join, Sort } from './common';
3
- import { Filter } from './filter';
4
-
5
- // Table operations
6
- export interface TableCreate {
7
- name: string;
8
- description?: string;
9
- columns: Column[];
10
- foreign_keys: ForeignKey[];
11
- indexes: Index[];
12
- }
13
-
14
- export interface TableDrop {
15
- name: string;
16
- }
17
-
18
- export interface TableRename {
19
- name: string;
20
- new_name: string;
21
- }
22
-
23
- export interface TableTruncate {
24
- name: string;
25
- }
26
-
27
- export interface TableAddColumn {
28
- table_name: string;
29
- column: Column;
30
- }
31
-
32
- export interface TableDropColumn {
33
- table_name: string;
34
- column_name: string;
35
- }
36
-
37
- export interface TableModifyColumn {
38
- table_name: string;
39
- column: Column;
40
- }
41
-
42
- export interface TableGetSchema {
43
- table_name: string;
44
- }
45
-
46
- // Data operations
47
- export interface InsertData {
48
- columns: string[];
49
- values: any[][];
50
- }
51
-
52
- export interface Insert {
53
- table_name: string;
54
- data: InsertData;
55
- }
56
-
57
- export interface UpdatePayload {
58
- filter: Filter;
59
- columns: string[];
60
- values: any[];
61
- }
62
-
63
- export interface Update {
64
- table_name: string;
65
- payload: UpdatePayload;
66
- }
67
-
68
- export interface DeleteDataPayload {
69
- filter: Filter;
70
- }
71
-
72
- export interface DeleteData {
73
- table_name: string;
74
- payload: DeleteDataPayload;
75
- }
76
-
77
- export interface QueryPayload {
78
- filter?: Filter;
79
- sort?: Sort[];
80
- aggregate?: Aggregate[];
81
- join?: Join[];
82
- limit?: number;
83
- offset?: number;
84
- group_by?: GroupBy;
85
- select?: string[];
86
- }
87
-
88
- export interface Query {
89
- table_name: string;
90
- query: QueryPayload;
91
- }
package/test.json DELETED
@@ -1,48 +0,0 @@
1
- {
2
- "name": "users",
3
- "description": "No description",
4
- "columns": [
5
- {
6
- "name": "id",
7
- "column_type": "Integer",
8
- "description": "",
9
- "is_primary_key": true,
10
- "is_nullable": false,
11
- "auto_increment": true
12
- },
13
- {
14
- "name": "email",
15
- "column_type": "text",
16
- "description": "",
17
- "is_primary_key": false,
18
- "is_nullable": false,
19
- "auto_increment": false
20
- },
21
- {
22
- "name": "full_name",
23
- "column_type": "text",
24
- "description": "",
25
- "is_primary_key": false,
26
- "is_nullable": false,
27
- "auto_increment": false
28
- },
29
- {
30
- "name": "profile",
31
- "column_type": "Json",
32
- "description": "",
33
- "is_primary_key": false,
34
- "is_nullable": true,
35
- "auto_increment": false
36
- },
37
- {
38
- "name": "is_active",
39
- "column_type": "Boolean",
40
- "description": "",
41
- "is_primary_key": false,
42
- "is_nullable": false,
43
- "auto_increment": false
44
- }
45
- ],
46
- "foreign_keys": [],
47
- "indexes": []
48
- }