@syntropix/database 0.0.1 → 0.0.3
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/.env +1 -1
- package/.vscode/settings.json +1 -8
- package/dist/core/client.d.ts +0 -1
- package/dist/core/client.js +2 -6
- package/dist/core/config.d.ts +0 -1
- package/dist/core/config.js +5 -6
- package/dist/core/dataClient.d.ts +0 -1
- package/dist/core/dataClient.js +4 -13
- package/dist/core/syntropix.d.ts +0 -1
- package/dist/core/syntropix.js +8 -10
- package/dist/core/tableClient.d.ts +2 -2
- package/dist/core/tableClient.js +4 -8
- package/dist/index.d.ts +0 -1
- package/dist/index.js +9 -33
- package/dist/types/basemodel.d.ts +2 -2
- package/dist/types/basemodel.js +32 -39
- package/dist/types/common.d.ts +1 -2
- package/dist/types/common.js +4 -8
- package/dist/types/data-type.d.ts +0 -1
- package/dist/types/data-type.js +18 -23
- package/dist/types/dto/base.d.ts +4 -0
- package/dist/types/dto/base.js +1 -0
- package/dist/types/dto/table.d.ts +22 -0
- package/dist/types/dto/table.js +1 -0
- package/dist/types/field.d.ts +0 -1
- package/dist/types/field.js +47 -62
- package/dist/types/filter.d.ts +0 -1
- package/dist/types/filter.js +35 -70
- package/dist/types/requests.d.ts +0 -1
- package/dist/types/requests.js +1 -3
- package/eslint.config.mjs +23 -23
- package/examples/tsconfig.json +13 -0
- package/examples/usage.ts +73 -52
- package/jest.config.ts +9 -0
- package/package.json +6 -5
- package/src/core/dataClient.ts +1 -6
- package/src/core/tableClient.ts +3 -2
- package/src/types/basemodel.ts +3 -2
- package/src/types/common.ts +83 -83
- package/src/types/dto/base.ts +4 -0
- package/src/types/dto/table.ts +21 -0
- package/src/types/filter.ts +28 -1
- package/src/types/requests.ts +2 -52
- package/tests/basic.test.ts +130 -62
- package/tests/tsconfig.json +8 -0
- package/tsconfig.json +18 -50
- package/dist/core/client.d.ts.map +0 -1
- package/dist/core/client.js.map +0 -1
- package/dist/core/config.d.ts.map +0 -1
- package/dist/core/config.js.map +0 -1
- package/dist/core/dataClient.d.ts.map +0 -1
- package/dist/core/dataClient.js.map +0 -1
- package/dist/core/syntropix.d.ts.map +0 -1
- package/dist/core/syntropix.js.map +0 -1
- package/dist/core/tableClient.d.ts.map +0 -1
- package/dist/core/tableClient.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types/basemodel.d.ts.map +0 -1
- package/dist/types/basemodel.js.map +0 -1
- package/dist/types/common.d.ts.map +0 -1
- package/dist/types/common.js.map +0 -1
- package/dist/types/data-type.d.ts.map +0 -1
- package/dist/types/data-type.js.map +0 -1
- package/dist/types/field.d.ts.map +0 -1
- package/dist/types/field.js.map +0 -1
- package/dist/types/filter.d.ts.map +0 -1
- package/dist/types/filter.js.map +0 -1
- package/dist/types/requests.d.ts.map +0 -1
- package/dist/types/requests.js.map +0 -1
- package/examples/advanced-usage.d.ts +0 -42
- package/examples/advanced-usage.d.ts.map +0 -1
- package/examples/advanced-usage.js +0 -257
- package/examples/advanced-usage.js.map +0 -1
- package/examples/usage.d.ts +0 -11
- package/examples/usage.d.ts.map +0 -1
- package/examples/usage.js +0 -91
- package/examples/usage.js.map +0 -1
- package/jest.config.js +0 -11
package/dist/types/field.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DoubleField = exports.DecimalField = exports.MoneyField = exports.EnumField = exports.ArrayField = exports.VectorField = exports.UuidField = exports.JsonField = exports.DateField = exports.TimestampField = exports.DateTimeField = exports.BooleanField = exports.IntegerField = exports.TextField = exports.StringField = exports.ForeignKeyField = exports.Field = void 0;
|
|
4
1
|
// Field definitions for ORM
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class Field {
|
|
2
|
+
import { ForeignKeyAction } from './common';
|
|
3
|
+
import { DataType } from './data-type';
|
|
4
|
+
export class Field {
|
|
5
|
+
name = '';
|
|
6
|
+
description = '';
|
|
7
|
+
column_type;
|
|
8
|
+
is_primary_key = false;
|
|
9
|
+
is_nullable = false;
|
|
10
|
+
auto_increment = false;
|
|
11
|
+
default;
|
|
8
12
|
constructor(column_type, options = {}) {
|
|
9
|
-
this.name = '';
|
|
10
|
-
this.description = '';
|
|
11
|
-
this.is_primary_key = false;
|
|
12
|
-
this.is_nullable = false;
|
|
13
|
-
this.auto_increment = false;
|
|
14
13
|
this.column_type = column_type;
|
|
15
14
|
this.name = options.name?.toLowerCase() || '';
|
|
16
15
|
this.description = options.description || '';
|
|
@@ -31,105 +30,91 @@ class Field {
|
|
|
31
30
|
};
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
export class ForeignKeyField extends Field {
|
|
34
|
+
tableName;
|
|
35
|
+
columnName;
|
|
36
|
+
onDelete;
|
|
37
|
+
onUpdate;
|
|
36
38
|
constructor(column_type, tableName, columnName, options = {}) {
|
|
37
39
|
super(column_type, options);
|
|
38
40
|
this.tableName = tableName;
|
|
39
41
|
this.columnName = columnName;
|
|
40
|
-
this.onDelete = options.onDelete ||
|
|
41
|
-
this.onUpdate = options.onUpdate ||
|
|
42
|
+
this.onDelete = options.onDelete || ForeignKeyAction.CASCADE;
|
|
43
|
+
this.onUpdate = options.onUpdate || ForeignKeyAction.CASCADE;
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
|
-
|
|
45
|
-
class StringField extends Field {
|
|
46
|
+
export class StringField extends Field {
|
|
46
47
|
constructor(maxLength, options = {}) {
|
|
47
|
-
super(
|
|
48
|
+
super(DataType.String(maxLength), options);
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
|
-
|
|
51
|
-
class TextField extends Field {
|
|
51
|
+
export class TextField extends Field {
|
|
52
52
|
constructor(options = {}) {
|
|
53
|
-
super(
|
|
53
|
+
super(DataType.Text, options);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
class IntegerField extends Field {
|
|
56
|
+
export class IntegerField extends Field {
|
|
58
57
|
constructor(options = {}) {
|
|
59
|
-
super(
|
|
58
|
+
super(DataType.Integer, options);
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
|
-
|
|
63
|
-
class BooleanField extends Field {
|
|
61
|
+
export class BooleanField extends Field {
|
|
64
62
|
constructor(options = {}) {
|
|
65
|
-
super(
|
|
63
|
+
super(DataType.Boolean, options);
|
|
66
64
|
}
|
|
67
65
|
}
|
|
68
|
-
|
|
69
|
-
class DateTimeField extends Field {
|
|
66
|
+
export class DateTimeField extends Field {
|
|
70
67
|
constructor(options = {}) {
|
|
71
|
-
super(
|
|
68
|
+
super(DataType.DateTime, options);
|
|
72
69
|
}
|
|
73
70
|
}
|
|
74
|
-
|
|
75
|
-
class TimestampField extends Field {
|
|
71
|
+
export class TimestampField extends Field {
|
|
76
72
|
constructor(options = {}) {
|
|
77
|
-
super(
|
|
73
|
+
super(DataType.Timestamp, options);
|
|
78
74
|
}
|
|
79
75
|
}
|
|
80
|
-
|
|
81
|
-
class DateField extends Field {
|
|
76
|
+
export class DateField extends Field {
|
|
82
77
|
constructor(options = {}) {
|
|
83
|
-
super(
|
|
78
|
+
super(DataType.Date, options);
|
|
84
79
|
}
|
|
85
80
|
}
|
|
86
|
-
|
|
87
|
-
class JsonField extends Field {
|
|
81
|
+
export class JsonField extends Field {
|
|
88
82
|
constructor(options = {}) {
|
|
89
|
-
super(
|
|
83
|
+
super(DataType.Json, options);
|
|
90
84
|
}
|
|
91
85
|
}
|
|
92
|
-
|
|
93
|
-
class UuidField extends Field {
|
|
86
|
+
export class UuidField extends Field {
|
|
94
87
|
constructor(options = {}) {
|
|
95
|
-
super(
|
|
88
|
+
super(DataType.Uuid, options);
|
|
96
89
|
}
|
|
97
90
|
}
|
|
98
|
-
|
|
99
|
-
class VectorField extends Field {
|
|
91
|
+
export class VectorField extends Field {
|
|
100
92
|
constructor(dimensions, options = {}) {
|
|
101
|
-
super(
|
|
93
|
+
super(DataType.Vector(dimensions), options);
|
|
102
94
|
}
|
|
103
95
|
}
|
|
104
|
-
|
|
105
|
-
class ArrayField extends Field {
|
|
96
|
+
export class ArrayField extends Field {
|
|
106
97
|
constructor(dataType, options = {}) {
|
|
107
|
-
super(
|
|
98
|
+
super(DataType.Array(dataType), options);
|
|
108
99
|
}
|
|
109
100
|
}
|
|
110
|
-
|
|
111
|
-
class EnumField extends Field {
|
|
101
|
+
export class EnumField extends Field {
|
|
112
102
|
constructor(name, variants, options = {}) {
|
|
113
|
-
super(
|
|
103
|
+
super(DataType.Enum(name, variants), options);
|
|
114
104
|
}
|
|
115
105
|
}
|
|
116
|
-
|
|
117
|
-
class MoneyField extends Field {
|
|
106
|
+
export class MoneyField extends Field {
|
|
118
107
|
constructor(precision, scale, options = {}) {
|
|
119
|
-
super(
|
|
108
|
+
super(DataType.Money(precision, scale), options);
|
|
120
109
|
}
|
|
121
110
|
}
|
|
122
|
-
|
|
123
|
-
class DecimalField extends Field {
|
|
111
|
+
export class DecimalField extends Field {
|
|
124
112
|
constructor(precision, scale, options = {}) {
|
|
125
|
-
super(
|
|
113
|
+
super(DataType.Decimal(precision, scale), options);
|
|
126
114
|
}
|
|
127
115
|
}
|
|
128
|
-
|
|
129
|
-
class DoubleField extends Field {
|
|
116
|
+
export class DoubleField extends Field {
|
|
130
117
|
constructor(options = {}) {
|
|
131
|
-
super(
|
|
118
|
+
super(DataType.Double, options);
|
|
132
119
|
}
|
|
133
120
|
}
|
|
134
|
-
exports.DoubleField = DoubleField;
|
|
135
|
-
//# sourceMappingURL=field.js.map
|
package/dist/types/filter.d.ts
CHANGED
|
@@ -73,4 +73,3 @@ export declare const EUCLIDEAN_DISTANCE: (field: string, value: any, options: Si
|
|
|
73
73
|
export declare const NEGATIVE_INNER_PRODUCT: (field: string, value: any, options: SimilarityOptions) => SyntropixDBFilterItem;
|
|
74
74
|
export declare const COSINE_DISTANCE: (field: string, value: any, options: SimilarityOptions) => SyntropixDBFilterItem;
|
|
75
75
|
export declare const Value: (value: any) => any;
|
|
76
|
-
//# sourceMappingURL=filter.d.ts.map
|
package/dist/types/filter.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Filter types for database queries
|
|
3
|
-
|
|
4
|
-
exports.Value = exports.COSINE_DISTANCE = exports.NEGATIVE_INNER_PRODUCT = exports.EUCLIDEAN_DISTANCE = exports.STRICT_WORD_SIMILARITY_DISTANCE = exports.STRICT_WORD_SIMILARITY = exports.WORD_SIMILARITY_DISTANCE = exports.WORD_SIMILARITY = exports.SIMILARITY_DISTANCE = exports.SIMILARITY = exports.LTE_COL = exports.LT_COL = exports.GTE_COL = exports.GT_COL = exports.NE_COL = exports.EQ_COL = exports.BETWEEN = exports.IS_NOT_NULL = exports.IS_NULL = exports.NOT_LIKE = exports.LIKE = exports.NOT_IN = exports.IN = exports.LTE = exports.LT = exports.GTE = exports.GT = exports.NE = exports.EQ = exports.OR = exports.AND = exports.FilterOperation = exports.SortType = void 0;
|
|
5
|
-
var SortType;
|
|
2
|
+
export var SortType;
|
|
6
3
|
(function (SortType) {
|
|
7
4
|
SortType["DESCENDING"] = "DESCENDING";
|
|
8
5
|
SortType["ASCENDING"] = "ASCENDING";
|
|
9
|
-
})(SortType || (
|
|
10
|
-
var FilterOperation;
|
|
6
|
+
})(SortType || (SortType = {}));
|
|
7
|
+
export var FilterOperation;
|
|
11
8
|
(function (FilterOperation) {
|
|
12
9
|
FilterOperation["LT"] = "LT";
|
|
13
10
|
FilterOperation["LTE"] = "LTE";
|
|
@@ -31,190 +28,158 @@ var FilterOperation;
|
|
|
31
28
|
FilterOperation["EuclideanDistance"] = "EuclideanDistance";
|
|
32
29
|
FilterOperation["NegativeInnerProduct"] = "NegativeInnerProduct";
|
|
33
30
|
FilterOperation["CosineDistance"] = "CosineDistance";
|
|
34
|
-
})(FilterOperation || (
|
|
31
|
+
})(FilterOperation || (FilterOperation = {}));
|
|
35
32
|
// Filter builder functions
|
|
36
|
-
const AND = (...conditions) => conditions;
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
exports.OR = OR;
|
|
40
|
-
const EQ = (field, value) => ({
|
|
33
|
+
export const AND = (...conditions) => conditions;
|
|
34
|
+
export const OR = (...conditions) => conditions;
|
|
35
|
+
export const EQ = (field, value) => ({
|
|
41
36
|
column: field,
|
|
42
37
|
operator: FilterOperation.EQ,
|
|
43
38
|
static_value: value,
|
|
44
39
|
});
|
|
45
|
-
|
|
46
|
-
const NE = (field, value) => ({
|
|
40
|
+
export const NE = (field, value) => ({
|
|
47
41
|
column: field,
|
|
48
42
|
operator: FilterOperation.NEQ,
|
|
49
43
|
static_value: value,
|
|
50
44
|
});
|
|
51
|
-
|
|
52
|
-
const GT = (field, value) => ({
|
|
45
|
+
export const GT = (field, value) => ({
|
|
53
46
|
column: field,
|
|
54
47
|
operator: FilterOperation.GT,
|
|
55
48
|
static_value: value,
|
|
56
49
|
});
|
|
57
|
-
|
|
58
|
-
const GTE = (field, value) => ({
|
|
50
|
+
export const GTE = (field, value) => ({
|
|
59
51
|
column: field,
|
|
60
52
|
operator: FilterOperation.GTE,
|
|
61
53
|
static_value: value,
|
|
62
54
|
});
|
|
63
|
-
|
|
64
|
-
const LT = (field, value) => ({
|
|
55
|
+
export const LT = (field, value) => ({
|
|
65
56
|
column: field,
|
|
66
57
|
operator: FilterOperation.LT,
|
|
67
58
|
static_value: value,
|
|
68
59
|
});
|
|
69
|
-
|
|
70
|
-
const LTE = (field, value) => ({
|
|
60
|
+
export const LTE = (field, value) => ({
|
|
71
61
|
column: field,
|
|
72
62
|
operator: FilterOperation.LTE,
|
|
73
63
|
static_value: value,
|
|
74
64
|
});
|
|
75
|
-
|
|
76
|
-
const IN = (field, values) => ({
|
|
65
|
+
export const IN = (field, values) => ({
|
|
77
66
|
column: field,
|
|
78
67
|
operator: FilterOperation.In,
|
|
79
68
|
static_value: values,
|
|
80
69
|
});
|
|
81
|
-
|
|
82
|
-
const NOT_IN = (field, values) => ({
|
|
70
|
+
export const NOT_IN = (field, values) => ({
|
|
83
71
|
column: field,
|
|
84
72
|
operator: FilterOperation.NotIn,
|
|
85
73
|
static_value: values,
|
|
86
74
|
});
|
|
87
|
-
|
|
88
|
-
const LIKE = (field, pattern) => ({
|
|
75
|
+
export const LIKE = (field, pattern) => ({
|
|
89
76
|
column: field,
|
|
90
77
|
operator: FilterOperation.Like,
|
|
91
78
|
static_value: pattern,
|
|
92
79
|
});
|
|
93
|
-
|
|
94
|
-
const NOT_LIKE = (field, pattern) => ({
|
|
80
|
+
export const NOT_LIKE = (field, pattern) => ({
|
|
95
81
|
column: field,
|
|
96
82
|
operator: FilterOperation.NotLike,
|
|
97
83
|
static_value: pattern,
|
|
98
84
|
});
|
|
99
|
-
|
|
100
|
-
const IS_NULL = (field) => ({
|
|
85
|
+
export const IS_NULL = (field) => ({
|
|
101
86
|
column: field,
|
|
102
87
|
operator: FilterOperation.IsNull,
|
|
103
88
|
});
|
|
104
|
-
|
|
105
|
-
const IS_NOT_NULL = (field) => ({
|
|
89
|
+
export const IS_NOT_NULL = (field) => ({
|
|
106
90
|
column: field,
|
|
107
91
|
operator: FilterOperation.IsNotNull,
|
|
108
92
|
});
|
|
109
|
-
|
|
110
|
-
const BETWEEN = (field, min, max) => ({
|
|
93
|
+
export const BETWEEN = (field, min, max) => ({
|
|
111
94
|
column: field,
|
|
112
95
|
operator: FilterOperation.Between,
|
|
113
96
|
static_value: [min, max],
|
|
114
97
|
});
|
|
115
|
-
exports.BETWEEN = BETWEEN;
|
|
116
98
|
// Column comparison (compare two columns)
|
|
117
|
-
const EQ_COL = (field, otherField) => ({
|
|
99
|
+
export const EQ_COL = (field, otherField) => ({
|
|
118
100
|
column: field,
|
|
119
101
|
operator: FilterOperation.EQ,
|
|
120
102
|
column_value: otherField,
|
|
121
103
|
});
|
|
122
|
-
|
|
123
|
-
const NE_COL = (field, otherField) => ({
|
|
104
|
+
export const NE_COL = (field, otherField) => ({
|
|
124
105
|
column: field,
|
|
125
106
|
operator: FilterOperation.NEQ,
|
|
126
107
|
column_value: otherField,
|
|
127
108
|
});
|
|
128
|
-
|
|
129
|
-
const GT_COL = (field, otherField) => ({
|
|
109
|
+
export const GT_COL = (field, otherField) => ({
|
|
130
110
|
column: field,
|
|
131
111
|
operator: FilterOperation.GT,
|
|
132
112
|
column_value: otherField,
|
|
133
113
|
});
|
|
134
|
-
|
|
135
|
-
const GTE_COL = (field, otherField) => ({
|
|
114
|
+
export const GTE_COL = (field, otherField) => ({
|
|
136
115
|
column: field,
|
|
137
116
|
operator: FilterOperation.GTE,
|
|
138
117
|
column_value: otherField,
|
|
139
118
|
});
|
|
140
|
-
|
|
141
|
-
const LT_COL = (field, otherField) => ({
|
|
119
|
+
export const LT_COL = (field, otherField) => ({
|
|
142
120
|
column: field,
|
|
143
121
|
operator: FilterOperation.LT,
|
|
144
122
|
column_value: otherField,
|
|
145
123
|
});
|
|
146
|
-
|
|
147
|
-
const LTE_COL = (field, otherField) => ({
|
|
124
|
+
export const LTE_COL = (field, otherField) => ({
|
|
148
125
|
column: field,
|
|
149
126
|
operator: FilterOperation.LTE,
|
|
150
127
|
column_value: otherField,
|
|
151
128
|
});
|
|
152
|
-
exports.LTE_COL = LTE_COL;
|
|
153
129
|
// Similarity operations
|
|
154
|
-
const SIMILARITY = (field, value, options) => ({
|
|
130
|
+
export const SIMILARITY = (field, value, options) => ({
|
|
155
131
|
column: field,
|
|
156
132
|
operator: FilterOperation.Similarity,
|
|
157
133
|
static_value: value,
|
|
158
134
|
similarity_options: options,
|
|
159
135
|
});
|
|
160
|
-
|
|
161
|
-
const SIMILARITY_DISTANCE = (field, value, options) => ({
|
|
136
|
+
export const SIMILARITY_DISTANCE = (field, value, options) => ({
|
|
162
137
|
column: field,
|
|
163
138
|
operator: FilterOperation.SimilarityDistance,
|
|
164
139
|
static_value: value,
|
|
165
140
|
similarity_options: options,
|
|
166
141
|
});
|
|
167
|
-
|
|
168
|
-
const WORD_SIMILARITY = (field, value, options) => ({
|
|
142
|
+
export const WORD_SIMILARITY = (field, value, options) => ({
|
|
169
143
|
column: field,
|
|
170
144
|
operator: FilterOperation.WordSimilarity,
|
|
171
145
|
static_value: value,
|
|
172
146
|
similarity_options: options,
|
|
173
147
|
});
|
|
174
|
-
|
|
175
|
-
const WORD_SIMILARITY_DISTANCE = (field, value, options) => ({
|
|
148
|
+
export const WORD_SIMILARITY_DISTANCE = (field, value, options) => ({
|
|
176
149
|
column: field,
|
|
177
150
|
operator: FilterOperation.WordSimilarityDistance,
|
|
178
151
|
static_value: value,
|
|
179
152
|
similarity_options: options,
|
|
180
153
|
});
|
|
181
|
-
|
|
182
|
-
const STRICT_WORD_SIMILARITY = (field, value, options) => ({
|
|
154
|
+
export const STRICT_WORD_SIMILARITY = (field, value, options) => ({
|
|
183
155
|
column: field,
|
|
184
156
|
operator: FilterOperation.StrictWordSimilarity,
|
|
185
157
|
static_value: value,
|
|
186
158
|
similarity_options: options,
|
|
187
159
|
});
|
|
188
|
-
|
|
189
|
-
const STRICT_WORD_SIMILARITY_DISTANCE = (field, value, options) => ({
|
|
160
|
+
export const STRICT_WORD_SIMILARITY_DISTANCE = (field, value, options) => ({
|
|
190
161
|
column: field,
|
|
191
162
|
operator: FilterOperation.StrictWordSimilarityDistance,
|
|
192
163
|
static_value: value,
|
|
193
164
|
similarity_options: options,
|
|
194
165
|
});
|
|
195
|
-
|
|
196
|
-
const EUCLIDEAN_DISTANCE = (field, value, options) => ({
|
|
166
|
+
export const EUCLIDEAN_DISTANCE = (field, value, options) => ({
|
|
197
167
|
column: field,
|
|
198
168
|
operator: FilterOperation.EuclideanDistance,
|
|
199
169
|
static_value: value,
|
|
200
170
|
similarity_options: options,
|
|
201
171
|
});
|
|
202
|
-
|
|
203
|
-
const NEGATIVE_INNER_PRODUCT = (field, value, options) => ({
|
|
172
|
+
export const NEGATIVE_INNER_PRODUCT = (field, value, options) => ({
|
|
204
173
|
column: field,
|
|
205
174
|
operator: FilterOperation.NegativeInnerProduct,
|
|
206
175
|
static_value: value,
|
|
207
176
|
similarity_options: options,
|
|
208
177
|
});
|
|
209
|
-
|
|
210
|
-
const COSINE_DISTANCE = (field, value, options) => ({
|
|
178
|
+
export const COSINE_DISTANCE = (field, value, options) => ({
|
|
211
179
|
column: field,
|
|
212
180
|
operator: FilterOperation.CosineDistance,
|
|
213
181
|
static_value: value,
|
|
214
182
|
similarity_options: options,
|
|
215
183
|
});
|
|
216
|
-
exports.COSINE_DISTANCE = COSINE_DISTANCE;
|
|
217
184
|
// Helper function for values (backward compatibility)
|
|
218
|
-
const Value = (value) => value;
|
|
219
|
-
exports.Value = Value;
|
|
220
|
-
//# sourceMappingURL=filter.js.map
|
|
185
|
+
export const Value = (value) => value;
|
package/dist/types/requests.d.ts
CHANGED
package/dist/types/requests.js
CHANGED
package/eslint.config.mjs
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import eslint from '@eslint/js';
|
|
2
|
-
import { defineConfig, globalIgnores } from 'eslint/config';
|
|
3
|
-
import tseslint from 'typescript-eslint';
|
|
4
|
-
|
|
5
|
-
export default defineConfig([
|
|
6
|
-
globalIgnores(['dist/**', 'node_modules/**', 'examples/**']),
|
|
7
|
-
eslint.configs.recommended,
|
|
8
|
-
...tseslint.configs.recommended,
|
|
9
|
-
{
|
|
10
|
-
files: ['**/*.ts', '**/*.tsx'],
|
|
11
|
-
languageOptions: {
|
|
12
|
-
parser: tseslint.parser,
|
|
13
|
-
parserOptions: {
|
|
14
|
-
project: './tsconfig.json',
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
rules: {
|
|
18
|
-
'no-unused-vars': 'off',
|
|
19
|
-
'@typescript-eslint/no-unused-vars': 'off',
|
|
20
|
-
'@typescript-eslint/no-explicit-any': 'off',
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
]);
|
|
1
|
+
import eslint from '@eslint/js';
|
|
2
|
+
import { defineConfig, globalIgnores } from 'eslint/config';
|
|
3
|
+
import tseslint from 'typescript-eslint';
|
|
4
|
+
|
|
5
|
+
export default defineConfig([
|
|
6
|
+
globalIgnores(['dist/**', 'node_modules/**', 'examples/**', 'tests/**', 'jest.config.ts']),
|
|
7
|
+
eslint.configs.recommended,
|
|
8
|
+
...tseslint.configs.recommended,
|
|
9
|
+
{
|
|
10
|
+
files: ['**/*.ts', '**/*.tsx'],
|
|
11
|
+
languageOptions: {
|
|
12
|
+
parser: tseslint.parser,
|
|
13
|
+
parserOptions: {
|
|
14
|
+
project: './tsconfig.json',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
rules: {
|
|
18
|
+
'no-unused-vars': 'off',
|
|
19
|
+
'@typescript-eslint/no-unused-vars': 'off',
|
|
20
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
]);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// This file is used to let VSCode respect the tsconfig.json for this test folder
|
|
2
|
+
{
|
|
3
|
+
"extends": "../tsconfig.json",
|
|
4
|
+
"include": [".", "../src"],
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"noEmit": true,
|
|
7
|
+
"baseUrl": ".",
|
|
8
|
+
"paths": {
|
|
9
|
+
"@syntropix/database": ["../src/index.ts"],
|
|
10
|
+
"@syntropix/database/*": ["../src/*"]
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
package/examples/usage.ts
CHANGED
|
@@ -1,73 +1,94 @@
|
|
|
1
|
-
|
|
1
|
+
import { AND, BaseModel, Column, EQ, IN, OR } from '@syntropix/database';
|
|
2
|
+
import { DataClient } from '@syntropix/database/core/dataClient';
|
|
3
|
+
import { TableClient } from '@syntropix/database/core/tableClient';
|
|
2
4
|
import 'dotenv/config';
|
|
3
|
-
import { BaseModel, Column } from '../dist/types/basemodel.js';
|
|
4
|
-
import { AND, EQ, OR } from '../dist/types/filter.js';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
export class User extends BaseModel {
|
|
6
|
+
class User extends BaseModel {
|
|
8
7
|
static tableName = 'users';
|
|
9
8
|
|
|
10
|
-
@Column({ type: 'Integer', primary: true, auto_increment: true })
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
@Column(
|
|
14
|
-
|
|
9
|
+
@Column({ type: 'Integer', primary: true, auto_increment: true })
|
|
10
|
+
declare id: number;
|
|
11
|
+
|
|
12
|
+
@Column()
|
|
13
|
+
declare email: string;
|
|
14
|
+
|
|
15
|
+
@Column({ name: 'full_name' })
|
|
16
|
+
declare fullName: string;
|
|
17
|
+
|
|
18
|
+
@Column({ type: 'Json', nullable: true })
|
|
19
|
+
declare profile: any;
|
|
20
|
+
|
|
21
|
+
@Column({ type: 'Boolean', name: 'is_active' })
|
|
22
|
+
declare isActive: boolean;
|
|
15
23
|
}
|
|
16
24
|
|
|
17
|
-
|
|
18
|
-
async function examples() {
|
|
25
|
+
async function ORMExample() {
|
|
19
26
|
// Create table
|
|
20
|
-
await User.createTable();
|
|
27
|
+
// await User.createTable();
|
|
21
28
|
|
|
22
29
|
// Create a new user
|
|
23
|
-
const newUser = await User.create({
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
});
|
|
30
|
+
// const newUser = await User.create({
|
|
31
|
+
// id: 1,
|
|
32
|
+
// email: 'user@example.com',
|
|
33
|
+
// fullName: 'John Doe',
|
|
34
|
+
// isActive: true,
|
|
35
|
+
// });
|
|
36
|
+
// console.log(newUser);
|
|
29
37
|
|
|
30
|
-
// Get a user
|
|
31
|
-
const user = await User.get(OR(AND(EQ('email', 'user@example.com'))));
|
|
32
|
-
console.log(user);
|
|
38
|
+
// // Get a user
|
|
39
|
+
// const user = await User.get(OR(AND(EQ('email', 'user@example.com'))));
|
|
40
|
+
// console.log(user);
|
|
33
41
|
|
|
34
|
-
// Update user
|
|
35
|
-
user.fullName = 'Jane Doe1';
|
|
36
|
-
await user.save();
|
|
42
|
+
// // Update user
|
|
43
|
+
// user.fullName = 'Jane Doe1';
|
|
44
|
+
// await user.save();
|
|
37
45
|
|
|
38
|
-
//
|
|
46
|
+
// Filter users
|
|
39
47
|
const activeUsers = await User.filter({
|
|
40
|
-
filter: OR(AND(
|
|
48
|
+
filter: OR(AND(IN('email', ['user@example.com', 'user3@example.com']))),
|
|
41
49
|
limit: 10,
|
|
42
50
|
});
|
|
43
51
|
|
|
44
|
-
// // Count users
|
|
45
|
-
const userCount = await User.count({
|
|
46
|
-
filter: OR(AND(EQ('is_active', true))),
|
|
47
|
-
});
|
|
48
52
|
console.log(activeUsers);
|
|
49
|
-
console.log(userCount);
|
|
50
|
-
// // Delete user
|
|
51
|
-
await user.remove();
|
|
52
|
-
|
|
53
|
-
// // Bulk create
|
|
54
|
-
await User.bulkCreate([
|
|
55
|
-
{
|
|
56
|
-
id: 2,
|
|
57
|
-
email: 'user2@example.com',
|
|
58
|
-
fullName: 'User 2',
|
|
59
|
-
isActive: true,
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
id: 3,
|
|
63
|
-
email: 'user3@example.com',
|
|
64
|
-
fullName: 'User 3',
|
|
65
|
-
isActive: false,
|
|
66
|
-
},
|
|
67
|
-
]);
|
|
68
53
|
|
|
69
|
-
//
|
|
54
|
+
// // // Count users
|
|
55
|
+
// const userCount = await User.count({
|
|
56
|
+
// filter: OR(AND(EQ('is_active', true))),
|
|
57
|
+
// });
|
|
58
|
+
// console.log(activeUsers);
|
|
59
|
+
// console.log(userCount);
|
|
60
|
+
// // // Delete user
|
|
61
|
+
// await user.remove();
|
|
62
|
+
|
|
63
|
+
// // // Bulk create
|
|
64
|
+
// await User.bulkCreate([
|
|
65
|
+
// {
|
|
66
|
+
// id: 2,
|
|
67
|
+
// email: 'user2@example.com',
|
|
68
|
+
// fullName: 'User 2',
|
|
69
|
+
// isActive: true,
|
|
70
|
+
// },
|
|
71
|
+
// {
|
|
72
|
+
// id: 3,
|
|
73
|
+
// email: 'user3@example.com',
|
|
74
|
+
// fullName: 'User 3',
|
|
75
|
+
// isActive: false,
|
|
76
|
+
// },
|
|
77
|
+
// ]);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function ClientExample() {
|
|
81
|
+
const tableClient = new TableClient();
|
|
82
|
+
const dataClient = new DataClient();
|
|
83
|
+
const data = await dataClient.queryMany({
|
|
84
|
+
table_name: 'users',
|
|
85
|
+
query: {
|
|
86
|
+
filter: OR(AND(EQ('is_active', true))),
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
console.log(data);
|
|
70
90
|
}
|
|
71
91
|
|
|
72
92
|
// Run examples
|
|
73
|
-
|
|
93
|
+
ORMExample().catch(console.error);
|
|
94
|
+
// ClientExample().catch(console.error);
|
package/jest.config.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Config } from 'jest';
|
|
2
|
+
import { createDefaultEsmPreset, pathsToModuleNameMapper } from 'ts-jest';
|
|
3
|
+
|
|
4
|
+
const presetConfig = createDefaultEsmPreset({});
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
...presetConfig,
|
|
8
|
+
moduleNameMapper: pathsToModuleNameMapper({ '@/*': ['src/*'] }, { prefix: '<rootDir>/' }),
|
|
9
|
+
} satisfies Config;
|