imean-cassandra-orm 1.0.0 → 1.1.0
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/README.md +31 -0
- package/dist/mod.cjs +11 -2
- package/dist/mod.d.cts +44 -4
- package/dist/mod.d.ts +44 -4
- package/dist/mod.js +11 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -135,6 +135,28 @@ type NonPartitionFields = InferNonPartitionFields<UserFields>;
|
|
|
135
135
|
// 推导结果: { name: string; age: number }
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
+
#### InferStaticFields<M>
|
|
139
|
+
|
|
140
|
+
推导静态字段类型。
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
const userModel = client.createModel({
|
|
144
|
+
id: Field.uuid().partitionKey(),
|
|
145
|
+
name: Field.text().static(), // 静态字段
|
|
146
|
+
age: Field.int().optional(),
|
|
147
|
+
email: Field.text(),
|
|
148
|
+
}, "users");
|
|
149
|
+
|
|
150
|
+
type UserStaticFields = InferStaticFields<typeof userModel>;
|
|
151
|
+
// 推导结果: { name: string }
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
静态列的特点:
|
|
155
|
+
1. 在分区级别存储数据,而不是在每一行重复存储
|
|
156
|
+
2. 适用于在分区内所有行共享相同值的字段
|
|
157
|
+
3. 可以节省存储空间
|
|
158
|
+
4. 提高查询效率
|
|
159
|
+
|
|
138
160
|
这些类型工具可以用于:
|
|
139
161
|
|
|
140
162
|
1. 在 API 层定义类型安全的接口
|
|
@@ -304,6 +326,15 @@ type UpdatableFields = {
|
|
|
304
326
|
Field.int().optional() // 将整数字段设置为可选
|
|
305
327
|
```
|
|
306
328
|
|
|
329
|
+
- `static(): this`
|
|
330
|
+
- 将字段设置为静态列
|
|
331
|
+
- 静态列在分区级别存储,而不是在每一行重复存储
|
|
332
|
+
- 适用于在分区内所有行共享相同值的字段
|
|
333
|
+
- 示例:
|
|
334
|
+
```typescript
|
|
335
|
+
Field.text().static() // 将文本字段设置为静态列
|
|
336
|
+
```
|
|
337
|
+
|
|
307
338
|
## 注意事项
|
|
308
339
|
|
|
309
340
|
1. 所有模型必须在调用 `syncAllSchemas` 之前创建
|
package/dist/mod.cjs
CHANGED
|
@@ -34,7 +34,8 @@ var Model = class {
|
|
|
34
34
|
getTableSchema() {
|
|
35
35
|
const columns = Object.entries(this.schema).map(([name, config]) => {
|
|
36
36
|
const type = config.type;
|
|
37
|
-
|
|
37
|
+
const staticFlag = config.flags.static ? " STATIC" : "";
|
|
38
|
+
return `${name} ${type}${staticFlag}`;
|
|
38
39
|
}).join(",\n ");
|
|
39
40
|
const primaryKey = this.clusteringKeys.length > 0 ? `((${this.partitionKeys.join(", ")}), ${this.clusteringKeys.join(
|
|
40
41
|
", "
|
|
@@ -244,7 +245,8 @@ var FieldBuilder = class _FieldBuilder {
|
|
|
244
245
|
constructor(type, flags = {
|
|
245
246
|
partitionKey: false,
|
|
246
247
|
clusteringKey: false,
|
|
247
|
-
optional: false
|
|
248
|
+
optional: false,
|
|
249
|
+
static: false
|
|
248
250
|
}) {
|
|
249
251
|
this.type = type;
|
|
250
252
|
this.flags = flags;
|
|
@@ -270,6 +272,13 @@ var FieldBuilder = class _FieldBuilder {
|
|
|
270
272
|
};
|
|
271
273
|
return new _FieldBuilder(this.type, newFlags);
|
|
272
274
|
}
|
|
275
|
+
static() {
|
|
276
|
+
const newFlags = {
|
|
277
|
+
...this.flags,
|
|
278
|
+
static: true
|
|
279
|
+
};
|
|
280
|
+
return new _FieldBuilder(this.type, newFlags);
|
|
281
|
+
}
|
|
273
282
|
};
|
|
274
283
|
var createField = (type) => {
|
|
275
284
|
return new FieldBuilder(type);
|
package/dist/mod.d.cts
CHANGED
|
@@ -25,6 +25,7 @@ type FieldConfig<T extends keyof TypeMap> = {
|
|
|
25
25
|
order: "ASC" | "DESC";
|
|
26
26
|
};
|
|
27
27
|
optional: boolean;
|
|
28
|
+
static: boolean;
|
|
28
29
|
};
|
|
29
30
|
};
|
|
30
31
|
declare class FieldBuilder<T extends keyof TypeMap, F extends {
|
|
@@ -33,10 +34,12 @@ declare class FieldBuilder<T extends keyof TypeMap, F extends {
|
|
|
33
34
|
order: "ASC" | "DESC";
|
|
34
35
|
};
|
|
35
36
|
optional: boolean;
|
|
37
|
+
static: boolean;
|
|
36
38
|
} = {
|
|
37
39
|
partitionKey: false;
|
|
38
40
|
clusteringKey: false;
|
|
39
41
|
optional: false;
|
|
42
|
+
static: false;
|
|
40
43
|
}> {
|
|
41
44
|
type: T;
|
|
42
45
|
flags: F;
|
|
@@ -52,8 +55,11 @@ declare class FieldBuilder<T extends keyof TypeMap, F extends {
|
|
|
52
55
|
optional(): FieldBuilder<T, Omit<F, "optional"> & {
|
|
53
56
|
optional: true;
|
|
54
57
|
}>;
|
|
58
|
+
static(): FieldBuilder<T, Omit<F, "static"> & {
|
|
59
|
+
static: true;
|
|
60
|
+
}>;
|
|
55
61
|
}
|
|
56
|
-
type InferFieldsByFlag<S extends Record<string, FieldConfig<keyof TypeMap>>, Flag extends "partitionKey" | "clusteringKey"> = {
|
|
62
|
+
type InferFieldsByFlag<S extends Record<string, FieldConfig<keyof TypeMap>>, Flag extends "partitionKey" | "clusteringKey" | "static"> = {
|
|
57
63
|
[K in keyof S as S[K]["flags"][Flag] extends true | {
|
|
58
64
|
order: "ASC" | "DESC";
|
|
59
65
|
} ? K : never]: InferType<S[K]["type"]>;
|
|
@@ -66,71 +72,85 @@ declare const Field: {
|
|
|
66
72
|
partitionKey: false;
|
|
67
73
|
clusteringKey: false;
|
|
68
74
|
optional: false;
|
|
75
|
+
static: false;
|
|
69
76
|
}>;
|
|
70
77
|
uuid: () => FieldBuilder<"uuid", {
|
|
71
78
|
partitionKey: false;
|
|
72
79
|
clusteringKey: false;
|
|
73
80
|
optional: false;
|
|
81
|
+
static: false;
|
|
74
82
|
}>;
|
|
75
83
|
int: () => FieldBuilder<"int", {
|
|
76
84
|
partitionKey: false;
|
|
77
85
|
clusteringKey: false;
|
|
78
86
|
optional: false;
|
|
87
|
+
static: false;
|
|
79
88
|
}>;
|
|
80
89
|
bigint: () => FieldBuilder<"bigint", {
|
|
81
90
|
partitionKey: false;
|
|
82
91
|
clusteringKey: false;
|
|
83
92
|
optional: false;
|
|
93
|
+
static: false;
|
|
84
94
|
}>;
|
|
85
95
|
varint: () => FieldBuilder<"varint", {
|
|
86
96
|
partitionKey: false;
|
|
87
97
|
clusteringKey: false;
|
|
88
98
|
optional: false;
|
|
99
|
+
static: false;
|
|
89
100
|
}>;
|
|
90
101
|
decimal: () => FieldBuilder<"decimal", {
|
|
91
102
|
partitionKey: false;
|
|
92
103
|
clusteringKey: false;
|
|
93
104
|
optional: false;
|
|
105
|
+
static: false;
|
|
94
106
|
}>;
|
|
95
107
|
float: () => FieldBuilder<"float", {
|
|
96
108
|
partitionKey: false;
|
|
97
109
|
clusteringKey: false;
|
|
98
110
|
optional: false;
|
|
111
|
+
static: false;
|
|
99
112
|
}>;
|
|
100
113
|
double: () => FieldBuilder<"double", {
|
|
101
114
|
partitionKey: false;
|
|
102
115
|
clusteringKey: false;
|
|
103
116
|
optional: false;
|
|
117
|
+
static: false;
|
|
104
118
|
}>;
|
|
105
119
|
boolean: () => FieldBuilder<"boolean", {
|
|
106
120
|
partitionKey: false;
|
|
107
121
|
clusteringKey: false;
|
|
108
122
|
optional: false;
|
|
123
|
+
static: false;
|
|
109
124
|
}>;
|
|
110
125
|
timestamp: () => FieldBuilder<"timestamp", {
|
|
111
126
|
partitionKey: false;
|
|
112
127
|
clusteringKey: false;
|
|
113
128
|
optional: false;
|
|
129
|
+
static: false;
|
|
114
130
|
}>;
|
|
115
131
|
blob: () => FieldBuilder<"blob", {
|
|
116
132
|
partitionKey: false;
|
|
117
133
|
clusteringKey: false;
|
|
118
134
|
optional: false;
|
|
135
|
+
static: false;
|
|
119
136
|
}>;
|
|
120
137
|
list: () => FieldBuilder<"list", {
|
|
121
138
|
partitionKey: false;
|
|
122
139
|
clusteringKey: false;
|
|
123
140
|
optional: false;
|
|
141
|
+
static: false;
|
|
124
142
|
}>;
|
|
125
143
|
set: () => FieldBuilder<"set", {
|
|
126
144
|
partitionKey: false;
|
|
127
145
|
clusteringKey: false;
|
|
128
146
|
optional: false;
|
|
147
|
+
static: false;
|
|
129
148
|
}>;
|
|
130
149
|
map: () => FieldBuilder<"map", {
|
|
131
150
|
partitionKey: false;
|
|
132
151
|
clusteringKey: false;
|
|
133
152
|
optional: false;
|
|
153
|
+
static: false;
|
|
134
154
|
}>;
|
|
135
155
|
};
|
|
136
156
|
|
|
@@ -205,6 +225,23 @@ type InferClusteringKey<M extends Model<any>> = M extends Model<infer S> ? Infer
|
|
|
205
225
|
type InferNonPartitionFields<S extends Record<string, FieldConfig<keyof TypeMap>>> = {
|
|
206
226
|
[K in keyof S as S[K]["flags"]["partitionKey"] extends true ? never : K]: InferType<S[K]["type"]>;
|
|
207
227
|
};
|
|
228
|
+
/**
|
|
229
|
+
* 推导静态字段类型
|
|
230
|
+
*
|
|
231
|
+
* @typeParam M - 继承自 Model 的类型
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* class User extends Model<{
|
|
236
|
+
* id: { type: "uuid"; flags: { partitionKey: true } };
|
|
237
|
+
* name: { type: "text"; flags: { static: true } };
|
|
238
|
+
* age: { type: "int" };
|
|
239
|
+
* }> {}
|
|
240
|
+
*
|
|
241
|
+
* type UserStaticFields = InferStaticFields<User>; // { name: string }
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
type InferStaticFields<M extends Model<any>> = M extends Model<infer S> ? InferFieldsByFlag<S, "static"> : never;
|
|
208
245
|
type Simplify<T> = T extends infer U ? {
|
|
209
246
|
[K in keyof U]: U[K];
|
|
210
247
|
} : never;
|
|
@@ -253,19 +290,22 @@ type orm_FieldBuilder<T extends keyof TypeMap, F extends {
|
|
|
253
290
|
order: "ASC" | "DESC";
|
|
254
291
|
};
|
|
255
292
|
optional: boolean;
|
|
293
|
+
static: boolean;
|
|
256
294
|
} = {
|
|
257
295
|
partitionKey: false;
|
|
258
296
|
clusteringKey: false;
|
|
259
297
|
optional: false;
|
|
298
|
+
static: false;
|
|
260
299
|
}> = FieldBuilder<T, F>;
|
|
261
300
|
declare const orm_FieldBuilder: typeof FieldBuilder;
|
|
262
301
|
type orm_FieldConfig<T extends keyof TypeMap> = FieldConfig<T>;
|
|
263
302
|
type orm_Infer<M extends Model<any>> = Infer<M>;
|
|
264
303
|
type orm_InferClusteringKey<M extends Model<any>> = InferClusteringKey<M>;
|
|
265
304
|
type orm_InferFields<S extends Record<string, FieldConfig<keyof TypeMap>>> = InferFields<S>;
|
|
266
|
-
type orm_InferFieldsByFlag<S extends Record<string, FieldConfig<keyof TypeMap>>, Flag extends "partitionKey" | "clusteringKey"> = InferFieldsByFlag<S, Flag>;
|
|
305
|
+
type orm_InferFieldsByFlag<S extends Record<string, FieldConfig<keyof TypeMap>>, Flag extends "partitionKey" | "clusteringKey" | "static"> = InferFieldsByFlag<S, Flag>;
|
|
267
306
|
type orm_InferNonPartitionFields<S extends Record<string, FieldConfig<keyof TypeMap>>> = InferNonPartitionFields<S>;
|
|
268
307
|
type orm_InferPartitionKey<M extends Model<any>> = InferPartitionKey<M>;
|
|
308
|
+
type orm_InferStaticFields<M extends Model<any>> = InferStaticFields<M>;
|
|
269
309
|
type orm_InferType<T extends keyof TypeMap> = InferType<T>;
|
|
270
310
|
type orm_Model<S extends Record<string, FieldConfig<keyof TypeMap>>, P = InferFieldsByFlag<S, "partitionKey">, C = InferFieldsByFlag<S, "clusteringKey">, NP = InferNonPartitionFields<S>, A = InferFields<S>> = Model<S, P, C, NP, A>;
|
|
271
311
|
declare const orm_Model: typeof Model;
|
|
@@ -273,7 +313,7 @@ type orm_Simplify<T> = Simplify<T>;
|
|
|
273
313
|
type orm_TypeMap = TypeMap;
|
|
274
314
|
declare const orm_uuid: typeof uuid;
|
|
275
315
|
declare namespace orm {
|
|
276
|
-
export { orm_Client as Client, orm_Field as Field, orm_FieldBuilder as FieldBuilder, type orm_FieldConfig as FieldConfig, type orm_Infer as Infer, type orm_InferClusteringKey as InferClusteringKey, type orm_InferFields as InferFields, type orm_InferFieldsByFlag as InferFieldsByFlag, type orm_InferNonPartitionFields as InferNonPartitionFields, type orm_InferPartitionKey as InferPartitionKey, type orm_InferType as InferType, orm_Model as Model, type orm_Simplify as Simplify, type orm_TypeMap as TypeMap, orm_uuid as uuid };
|
|
316
|
+
export { orm_Client as Client, orm_Field as Field, orm_FieldBuilder as FieldBuilder, type orm_FieldConfig as FieldConfig, type orm_Infer as Infer, type orm_InferClusteringKey as InferClusteringKey, type orm_InferFields as InferFields, type orm_InferFieldsByFlag as InferFieldsByFlag, type orm_InferNonPartitionFields as InferNonPartitionFields, type orm_InferPartitionKey as InferPartitionKey, type orm_InferStaticFields as InferStaticFields, type orm_InferType as InferType, orm_Model as Model, type orm_Simplify as Simplify, type orm_TypeMap as TypeMap, orm_uuid as uuid };
|
|
277
317
|
}
|
|
278
318
|
|
|
279
|
-
export { Client, Field, FieldBuilder, type FieldConfig, type Infer, type InferClusteringKey, type InferFields, type InferFieldsByFlag, type InferNonPartitionFields, type InferPartitionKey, type InferType, Model, type Simplify, type TypeMap, orm as default, uuid };
|
|
319
|
+
export { Client, Field, FieldBuilder, type FieldConfig, type Infer, type InferClusteringKey, type InferFields, type InferFieldsByFlag, type InferNonPartitionFields, type InferPartitionKey, type InferStaticFields, type InferType, Model, type Simplify, type TypeMap, orm as default, uuid };
|
package/dist/mod.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ type FieldConfig<T extends keyof TypeMap> = {
|
|
|
25
25
|
order: "ASC" | "DESC";
|
|
26
26
|
};
|
|
27
27
|
optional: boolean;
|
|
28
|
+
static: boolean;
|
|
28
29
|
};
|
|
29
30
|
};
|
|
30
31
|
declare class FieldBuilder<T extends keyof TypeMap, F extends {
|
|
@@ -33,10 +34,12 @@ declare class FieldBuilder<T extends keyof TypeMap, F extends {
|
|
|
33
34
|
order: "ASC" | "DESC";
|
|
34
35
|
};
|
|
35
36
|
optional: boolean;
|
|
37
|
+
static: boolean;
|
|
36
38
|
} = {
|
|
37
39
|
partitionKey: false;
|
|
38
40
|
clusteringKey: false;
|
|
39
41
|
optional: false;
|
|
42
|
+
static: false;
|
|
40
43
|
}> {
|
|
41
44
|
type: T;
|
|
42
45
|
flags: F;
|
|
@@ -52,8 +55,11 @@ declare class FieldBuilder<T extends keyof TypeMap, F extends {
|
|
|
52
55
|
optional(): FieldBuilder<T, Omit<F, "optional"> & {
|
|
53
56
|
optional: true;
|
|
54
57
|
}>;
|
|
58
|
+
static(): FieldBuilder<T, Omit<F, "static"> & {
|
|
59
|
+
static: true;
|
|
60
|
+
}>;
|
|
55
61
|
}
|
|
56
|
-
type InferFieldsByFlag<S extends Record<string, FieldConfig<keyof TypeMap>>, Flag extends "partitionKey" | "clusteringKey"> = {
|
|
62
|
+
type InferFieldsByFlag<S extends Record<string, FieldConfig<keyof TypeMap>>, Flag extends "partitionKey" | "clusteringKey" | "static"> = {
|
|
57
63
|
[K in keyof S as S[K]["flags"][Flag] extends true | {
|
|
58
64
|
order: "ASC" | "DESC";
|
|
59
65
|
} ? K : never]: InferType<S[K]["type"]>;
|
|
@@ -66,71 +72,85 @@ declare const Field: {
|
|
|
66
72
|
partitionKey: false;
|
|
67
73
|
clusteringKey: false;
|
|
68
74
|
optional: false;
|
|
75
|
+
static: false;
|
|
69
76
|
}>;
|
|
70
77
|
uuid: () => FieldBuilder<"uuid", {
|
|
71
78
|
partitionKey: false;
|
|
72
79
|
clusteringKey: false;
|
|
73
80
|
optional: false;
|
|
81
|
+
static: false;
|
|
74
82
|
}>;
|
|
75
83
|
int: () => FieldBuilder<"int", {
|
|
76
84
|
partitionKey: false;
|
|
77
85
|
clusteringKey: false;
|
|
78
86
|
optional: false;
|
|
87
|
+
static: false;
|
|
79
88
|
}>;
|
|
80
89
|
bigint: () => FieldBuilder<"bigint", {
|
|
81
90
|
partitionKey: false;
|
|
82
91
|
clusteringKey: false;
|
|
83
92
|
optional: false;
|
|
93
|
+
static: false;
|
|
84
94
|
}>;
|
|
85
95
|
varint: () => FieldBuilder<"varint", {
|
|
86
96
|
partitionKey: false;
|
|
87
97
|
clusteringKey: false;
|
|
88
98
|
optional: false;
|
|
99
|
+
static: false;
|
|
89
100
|
}>;
|
|
90
101
|
decimal: () => FieldBuilder<"decimal", {
|
|
91
102
|
partitionKey: false;
|
|
92
103
|
clusteringKey: false;
|
|
93
104
|
optional: false;
|
|
105
|
+
static: false;
|
|
94
106
|
}>;
|
|
95
107
|
float: () => FieldBuilder<"float", {
|
|
96
108
|
partitionKey: false;
|
|
97
109
|
clusteringKey: false;
|
|
98
110
|
optional: false;
|
|
111
|
+
static: false;
|
|
99
112
|
}>;
|
|
100
113
|
double: () => FieldBuilder<"double", {
|
|
101
114
|
partitionKey: false;
|
|
102
115
|
clusteringKey: false;
|
|
103
116
|
optional: false;
|
|
117
|
+
static: false;
|
|
104
118
|
}>;
|
|
105
119
|
boolean: () => FieldBuilder<"boolean", {
|
|
106
120
|
partitionKey: false;
|
|
107
121
|
clusteringKey: false;
|
|
108
122
|
optional: false;
|
|
123
|
+
static: false;
|
|
109
124
|
}>;
|
|
110
125
|
timestamp: () => FieldBuilder<"timestamp", {
|
|
111
126
|
partitionKey: false;
|
|
112
127
|
clusteringKey: false;
|
|
113
128
|
optional: false;
|
|
129
|
+
static: false;
|
|
114
130
|
}>;
|
|
115
131
|
blob: () => FieldBuilder<"blob", {
|
|
116
132
|
partitionKey: false;
|
|
117
133
|
clusteringKey: false;
|
|
118
134
|
optional: false;
|
|
135
|
+
static: false;
|
|
119
136
|
}>;
|
|
120
137
|
list: () => FieldBuilder<"list", {
|
|
121
138
|
partitionKey: false;
|
|
122
139
|
clusteringKey: false;
|
|
123
140
|
optional: false;
|
|
141
|
+
static: false;
|
|
124
142
|
}>;
|
|
125
143
|
set: () => FieldBuilder<"set", {
|
|
126
144
|
partitionKey: false;
|
|
127
145
|
clusteringKey: false;
|
|
128
146
|
optional: false;
|
|
147
|
+
static: false;
|
|
129
148
|
}>;
|
|
130
149
|
map: () => FieldBuilder<"map", {
|
|
131
150
|
partitionKey: false;
|
|
132
151
|
clusteringKey: false;
|
|
133
152
|
optional: false;
|
|
153
|
+
static: false;
|
|
134
154
|
}>;
|
|
135
155
|
};
|
|
136
156
|
|
|
@@ -205,6 +225,23 @@ type InferClusteringKey<M extends Model<any>> = M extends Model<infer S> ? Infer
|
|
|
205
225
|
type InferNonPartitionFields<S extends Record<string, FieldConfig<keyof TypeMap>>> = {
|
|
206
226
|
[K in keyof S as S[K]["flags"]["partitionKey"] extends true ? never : K]: InferType<S[K]["type"]>;
|
|
207
227
|
};
|
|
228
|
+
/**
|
|
229
|
+
* 推导静态字段类型
|
|
230
|
+
*
|
|
231
|
+
* @typeParam M - 继承自 Model 的类型
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* class User extends Model<{
|
|
236
|
+
* id: { type: "uuid"; flags: { partitionKey: true } };
|
|
237
|
+
* name: { type: "text"; flags: { static: true } };
|
|
238
|
+
* age: { type: "int" };
|
|
239
|
+
* }> {}
|
|
240
|
+
*
|
|
241
|
+
* type UserStaticFields = InferStaticFields<User>; // { name: string }
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
type InferStaticFields<M extends Model<any>> = M extends Model<infer S> ? InferFieldsByFlag<S, "static"> : never;
|
|
208
245
|
type Simplify<T> = T extends infer U ? {
|
|
209
246
|
[K in keyof U]: U[K];
|
|
210
247
|
} : never;
|
|
@@ -253,19 +290,22 @@ type orm_FieldBuilder<T extends keyof TypeMap, F extends {
|
|
|
253
290
|
order: "ASC" | "DESC";
|
|
254
291
|
};
|
|
255
292
|
optional: boolean;
|
|
293
|
+
static: boolean;
|
|
256
294
|
} = {
|
|
257
295
|
partitionKey: false;
|
|
258
296
|
clusteringKey: false;
|
|
259
297
|
optional: false;
|
|
298
|
+
static: false;
|
|
260
299
|
}> = FieldBuilder<T, F>;
|
|
261
300
|
declare const orm_FieldBuilder: typeof FieldBuilder;
|
|
262
301
|
type orm_FieldConfig<T extends keyof TypeMap> = FieldConfig<T>;
|
|
263
302
|
type orm_Infer<M extends Model<any>> = Infer<M>;
|
|
264
303
|
type orm_InferClusteringKey<M extends Model<any>> = InferClusteringKey<M>;
|
|
265
304
|
type orm_InferFields<S extends Record<string, FieldConfig<keyof TypeMap>>> = InferFields<S>;
|
|
266
|
-
type orm_InferFieldsByFlag<S extends Record<string, FieldConfig<keyof TypeMap>>, Flag extends "partitionKey" | "clusteringKey"> = InferFieldsByFlag<S, Flag>;
|
|
305
|
+
type orm_InferFieldsByFlag<S extends Record<string, FieldConfig<keyof TypeMap>>, Flag extends "partitionKey" | "clusteringKey" | "static"> = InferFieldsByFlag<S, Flag>;
|
|
267
306
|
type orm_InferNonPartitionFields<S extends Record<string, FieldConfig<keyof TypeMap>>> = InferNonPartitionFields<S>;
|
|
268
307
|
type orm_InferPartitionKey<M extends Model<any>> = InferPartitionKey<M>;
|
|
308
|
+
type orm_InferStaticFields<M extends Model<any>> = InferStaticFields<M>;
|
|
269
309
|
type orm_InferType<T extends keyof TypeMap> = InferType<T>;
|
|
270
310
|
type orm_Model<S extends Record<string, FieldConfig<keyof TypeMap>>, P = InferFieldsByFlag<S, "partitionKey">, C = InferFieldsByFlag<S, "clusteringKey">, NP = InferNonPartitionFields<S>, A = InferFields<S>> = Model<S, P, C, NP, A>;
|
|
271
311
|
declare const orm_Model: typeof Model;
|
|
@@ -273,7 +313,7 @@ type orm_Simplify<T> = Simplify<T>;
|
|
|
273
313
|
type orm_TypeMap = TypeMap;
|
|
274
314
|
declare const orm_uuid: typeof uuid;
|
|
275
315
|
declare namespace orm {
|
|
276
|
-
export { orm_Client as Client, orm_Field as Field, orm_FieldBuilder as FieldBuilder, type orm_FieldConfig as FieldConfig, type orm_Infer as Infer, type orm_InferClusteringKey as InferClusteringKey, type orm_InferFields as InferFields, type orm_InferFieldsByFlag as InferFieldsByFlag, type orm_InferNonPartitionFields as InferNonPartitionFields, type orm_InferPartitionKey as InferPartitionKey, type orm_InferType as InferType, orm_Model as Model, type orm_Simplify as Simplify, type orm_TypeMap as TypeMap, orm_uuid as uuid };
|
|
316
|
+
export { orm_Client as Client, orm_Field as Field, orm_FieldBuilder as FieldBuilder, type orm_FieldConfig as FieldConfig, type orm_Infer as Infer, type orm_InferClusteringKey as InferClusteringKey, type orm_InferFields as InferFields, type orm_InferFieldsByFlag as InferFieldsByFlag, type orm_InferNonPartitionFields as InferNonPartitionFields, type orm_InferPartitionKey as InferPartitionKey, type orm_InferStaticFields as InferStaticFields, type orm_InferType as InferType, orm_Model as Model, type orm_Simplify as Simplify, type orm_TypeMap as TypeMap, orm_uuid as uuid };
|
|
277
317
|
}
|
|
278
318
|
|
|
279
|
-
export { Client, Field, FieldBuilder, type FieldConfig, type Infer, type InferClusteringKey, type InferFields, type InferFieldsByFlag, type InferNonPartitionFields, type InferPartitionKey, type InferType, Model, type Simplify, type TypeMap, orm as default, uuid };
|
|
319
|
+
export { Client, Field, FieldBuilder, type FieldConfig, type Infer, type InferClusteringKey, type InferFields, type InferFieldsByFlag, type InferNonPartitionFields, type InferPartitionKey, type InferStaticFields, type InferType, Model, type Simplify, type TypeMap, orm as default, uuid };
|
package/dist/mod.js
CHANGED
|
@@ -30,7 +30,8 @@ var Model = class {
|
|
|
30
30
|
getTableSchema() {
|
|
31
31
|
const columns = Object.entries(this.schema).map(([name, config]) => {
|
|
32
32
|
const type = config.type;
|
|
33
|
-
|
|
33
|
+
const staticFlag = config.flags.static ? " STATIC" : "";
|
|
34
|
+
return `${name} ${type}${staticFlag}`;
|
|
34
35
|
}).join(",\n ");
|
|
35
36
|
const primaryKey = this.clusteringKeys.length > 0 ? `((${this.partitionKeys.join(", ")}), ${this.clusteringKeys.join(
|
|
36
37
|
", "
|
|
@@ -240,7 +241,8 @@ var FieldBuilder = class _FieldBuilder {
|
|
|
240
241
|
constructor(type, flags = {
|
|
241
242
|
partitionKey: false,
|
|
242
243
|
clusteringKey: false,
|
|
243
|
-
optional: false
|
|
244
|
+
optional: false,
|
|
245
|
+
static: false
|
|
244
246
|
}) {
|
|
245
247
|
this.type = type;
|
|
246
248
|
this.flags = flags;
|
|
@@ -266,6 +268,13 @@ var FieldBuilder = class _FieldBuilder {
|
|
|
266
268
|
};
|
|
267
269
|
return new _FieldBuilder(this.type, newFlags);
|
|
268
270
|
}
|
|
271
|
+
static() {
|
|
272
|
+
const newFlags = {
|
|
273
|
+
...this.flags,
|
|
274
|
+
static: true
|
|
275
|
+
};
|
|
276
|
+
return new _FieldBuilder(this.type, newFlags);
|
|
277
|
+
}
|
|
269
278
|
};
|
|
270
279
|
var createField = (type) => {
|
|
271
280
|
return new FieldBuilder(type);
|