imean-cassandra-orm 2.0.0 → 2.0.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/mod.cjs +48 -5
- package/dist/mod.d.cts +10 -0
- package/dist/mod.d.ts +10 -0
- package/dist/mod.js +48 -5
- package/package.json +1 -1
package/dist/mod.cjs
CHANGED
|
@@ -442,6 +442,12 @@ var Model = class _Model {
|
|
|
442
442
|
this.schema = schema;
|
|
443
443
|
this.client = client;
|
|
444
444
|
}
|
|
445
|
+
get types() {
|
|
446
|
+
return this.schema.types;
|
|
447
|
+
}
|
|
448
|
+
get schemas() {
|
|
449
|
+
return this.schema.schemas;
|
|
450
|
+
}
|
|
445
451
|
// 静态方法:创建模型(需要外部传入 client)
|
|
446
452
|
static create(definition, client) {
|
|
447
453
|
const schema = new TableSchema(definition);
|
|
@@ -577,13 +583,46 @@ var Model = class _Model {
|
|
|
577
583
|
syncQueries.push(queryHelper.dropColumns(this.schema, deletedFields));
|
|
578
584
|
}
|
|
579
585
|
if (updatedFields.length > 0) {
|
|
580
|
-
|
|
586
|
+
const fieldDetails = updatedFields.map((field) => {
|
|
587
|
+
const existingType = tableMetadata2.find((t) => t.column_name === field)?.type || "unknown";
|
|
588
|
+
const newType = convertZodToCassandraType(
|
|
589
|
+
this.schema.fields.shape[field]
|
|
590
|
+
);
|
|
591
|
+
return `${field}(${existingType} -> ${newType})`;
|
|
592
|
+
}).join(", ");
|
|
593
|
+
errorReason = `\u5B57\u6BB5\u7C7B\u578B\u6709\u66F4\u65B0\uFF0C\u65E0\u6CD5\u81EA\u52A8\u66F4\u65B0\u3002\u53D8\u66F4\u5B57\u6BB5: ${fieldDetails}`;
|
|
581
594
|
}
|
|
582
595
|
if (hasKeyFieldChanged(this.schema, newFields, deletedFields)) {
|
|
583
|
-
|
|
596
|
+
const partitionKeyFields = this.schema.partitionKeyFields;
|
|
597
|
+
const clusteringKeyFields = this.schema.clusteringKeyFields.map(
|
|
598
|
+
(ck) => ck.field
|
|
599
|
+
);
|
|
600
|
+
const keyFields = [...partitionKeyFields, ...clusteringKeyFields];
|
|
601
|
+
const newKeyFields = newFields.filter(
|
|
602
|
+
(field) => keyFields.includes(field)
|
|
603
|
+
);
|
|
604
|
+
const deletedKeyFields = deletedFields.filter(
|
|
605
|
+
(field) => keyFields.includes(field)
|
|
606
|
+
);
|
|
607
|
+
let keyChangeDetails = [];
|
|
608
|
+
if (newKeyFields.length > 0) {
|
|
609
|
+
keyChangeDetails.push(`\u65B0\u589E\u952E\u5B57\u6BB5: ${newKeyFields.join(", ")}`);
|
|
610
|
+
}
|
|
611
|
+
if (deletedKeyFields.length > 0) {
|
|
612
|
+
keyChangeDetails.push(`\u5220\u9664\u952E\u5B57\u6BB5: ${deletedKeyFields.join(", ")}`);
|
|
613
|
+
}
|
|
614
|
+
errorReason = `\u952E\u5B57\u6BB5\u53D1\u751F\u53D8\u66F4\uFF0C\u65E0\u6CD5\u81EA\u52A8\u66F4\u65B0\u3002${keyChangeDetails.join(
|
|
615
|
+
"; "
|
|
616
|
+
)}`;
|
|
584
617
|
}
|
|
585
618
|
if (isClusteringKeyChanged(this.schema, tableMetadata2)) {
|
|
586
|
-
|
|
619
|
+
const existingClusteringKeys = tableMetadata2.filter((t) => t.kind === "clustering").map((t) => t.column_name);
|
|
620
|
+
const currentClusteringKeys = this.schema.clusteringKeyFields.map(
|
|
621
|
+
(ck) => ck.field
|
|
622
|
+
);
|
|
623
|
+
const existingOrder = existingClusteringKeys.join(", ");
|
|
624
|
+
const currentOrder = currentClusteringKeys.join(", ");
|
|
625
|
+
errorReason = `\u805A\u7C7B\u952E\u914D\u7F6E\u53D1\u751F\u53D8\u5316\uFF0C\u65E0\u6CD5\u81EA\u52A8\u66F4\u65B0\u3002\u73B0\u6709\u987A\u5E8F: [${existingOrder}]\uFF0C\u65B0\u987A\u5E8F: [${currentOrder}]`;
|
|
587
626
|
}
|
|
588
627
|
}
|
|
589
628
|
if (errorReason) {
|
|
@@ -613,7 +652,7 @@ var uuid = () => cassandraDriver.types.Uuid.random().toString();
|
|
|
613
652
|
var Client = class {
|
|
614
653
|
constructor(options) {
|
|
615
654
|
this.options = options;
|
|
616
|
-
this.cassandraClient = new cassandraDriver.Client(options);
|
|
655
|
+
this.cassandraClient = new cassandraDriver.Client({ ...options });
|
|
617
656
|
}
|
|
618
657
|
cassandraClient;
|
|
619
658
|
models = [];
|
|
@@ -663,7 +702,11 @@ var Client = class {
|
|
|
663
702
|
}
|
|
664
703
|
}
|
|
665
704
|
try {
|
|
666
|
-
const result = await this.cassandraClient.execute(
|
|
705
|
+
const result = await this.cassandraClient.execute(
|
|
706
|
+
cql,
|
|
707
|
+
params,
|
|
708
|
+
executeOptions
|
|
709
|
+
);
|
|
667
710
|
if (this.options.debug) {
|
|
668
711
|
console.log({ query: cql, params, rows: result.rows });
|
|
669
712
|
}
|
package/dist/mod.d.cts
CHANGED
|
@@ -179,6 +179,16 @@ declare class Model<F extends z.ZodRawShape, PK extends (keyof F)[], CK extends
|
|
|
179
179
|
readonly schema: TableSchema<F, PK, CK>;
|
|
180
180
|
readonly client: Client;
|
|
181
181
|
constructor(schema: TableSchema<F, PK, CK>, client: Client);
|
|
182
|
+
get types(): {
|
|
183
|
+
model: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<F>, any> extends infer T ? { [k in keyof T]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<F>, any>[k]; } : never;
|
|
184
|
+
partitionKey: ExtractPartitionKeyType<F, PK>;
|
|
185
|
+
clusteringKey: ExtractClusteringKeyType<F, CK>;
|
|
186
|
+
};
|
|
187
|
+
get schemas(): {
|
|
188
|
+
model: z.ZodObject<F, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<F>, any> extends infer T ? { [k in keyof T]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<F>, any>[k]; } : never, z.baseObjectInputType<F> extends infer T_1 ? { [k_1 in keyof T_1]: z.baseObjectInputType<F>[k_1]; } : never>;
|
|
189
|
+
partitionKey: z.ZodObject<ExtractPartitionKeyShape<F, PK>, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<ExtractPartitionKeyShape<F, PK>>, any> extends infer T_2 ? { [k_2 in keyof T_2]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<ExtractPartitionKeyShape<F, PK>>, any>[k_2]; } : never, z.baseObjectInputType<ExtractPartitionKeyShape<F, PK>> extends infer T_3 ? { [k_3 in keyof T_3]: z.baseObjectInputType<ExtractPartitionKeyShape<F, PK>>[k_3]; } : never>;
|
|
190
|
+
clusteringKey: CK extends ClusteringKeyConfig ? z.ZodObject<ExtractClusteringKeyShape<F, CK>, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<ExtractClusteringKeyShape<F, CK>>, any> extends infer T_4 ? { [k_4 in keyof T_4]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<ExtractClusteringKeyShape<F, CK>>, any>[k_4]; } : never, z.baseObjectInputType<ExtractClusteringKeyShape<F, CK>> extends infer T_5 ? { [k_5 in keyof T_5]: z.baseObjectInputType<ExtractClusteringKeyShape<F, CK>>[k_5]; } : never> : never;
|
|
191
|
+
};
|
|
182
192
|
static create<F extends z.ZodRawShape, PK extends (keyof F)[], CK extends ClusteringKeyConfig | undefined = undefined>(definition: SchemaDefinition<F, PK, CK>, client: Client): Model<F, PK, CK>;
|
|
183
193
|
insert(data: z.infer<z.ZodObject<F>>): Promise<void>;
|
|
184
194
|
batchInsert(data: z.infer<z.ZodObject<F>>[]): Promise<void>;
|
package/dist/mod.d.ts
CHANGED
|
@@ -179,6 +179,16 @@ declare class Model<F extends z.ZodRawShape, PK extends (keyof F)[], CK extends
|
|
|
179
179
|
readonly schema: TableSchema<F, PK, CK>;
|
|
180
180
|
readonly client: Client;
|
|
181
181
|
constructor(schema: TableSchema<F, PK, CK>, client: Client);
|
|
182
|
+
get types(): {
|
|
183
|
+
model: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<F>, any> extends infer T ? { [k in keyof T]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<F>, any>[k]; } : never;
|
|
184
|
+
partitionKey: ExtractPartitionKeyType<F, PK>;
|
|
185
|
+
clusteringKey: ExtractClusteringKeyType<F, CK>;
|
|
186
|
+
};
|
|
187
|
+
get schemas(): {
|
|
188
|
+
model: z.ZodObject<F, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<F>, any> extends infer T ? { [k in keyof T]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<F>, any>[k]; } : never, z.baseObjectInputType<F> extends infer T_1 ? { [k_1 in keyof T_1]: z.baseObjectInputType<F>[k_1]; } : never>;
|
|
189
|
+
partitionKey: z.ZodObject<ExtractPartitionKeyShape<F, PK>, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<ExtractPartitionKeyShape<F, PK>>, any> extends infer T_2 ? { [k_2 in keyof T_2]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<ExtractPartitionKeyShape<F, PK>>, any>[k_2]; } : never, z.baseObjectInputType<ExtractPartitionKeyShape<F, PK>> extends infer T_3 ? { [k_3 in keyof T_3]: z.baseObjectInputType<ExtractPartitionKeyShape<F, PK>>[k_3]; } : never>;
|
|
190
|
+
clusteringKey: CK extends ClusteringKeyConfig ? z.ZodObject<ExtractClusteringKeyShape<F, CK>, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<ExtractClusteringKeyShape<F, CK>>, any> extends infer T_4 ? { [k_4 in keyof T_4]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<ExtractClusteringKeyShape<F, CK>>, any>[k_4]; } : never, z.baseObjectInputType<ExtractClusteringKeyShape<F, CK>> extends infer T_5 ? { [k_5 in keyof T_5]: z.baseObjectInputType<ExtractClusteringKeyShape<F, CK>>[k_5]; } : never> : never;
|
|
191
|
+
};
|
|
182
192
|
static create<F extends z.ZodRawShape, PK extends (keyof F)[], CK extends ClusteringKeyConfig | undefined = undefined>(definition: SchemaDefinition<F, PK, CK>, client: Client): Model<F, PK, CK>;
|
|
183
193
|
insert(data: z.infer<z.ZodObject<F>>): Promise<void>;
|
|
184
194
|
batchInsert(data: z.infer<z.ZodObject<F>>[]): Promise<void>;
|
package/dist/mod.js
CHANGED
|
@@ -440,6 +440,12 @@ var Model = class _Model {
|
|
|
440
440
|
this.schema = schema;
|
|
441
441
|
this.client = client;
|
|
442
442
|
}
|
|
443
|
+
get types() {
|
|
444
|
+
return this.schema.types;
|
|
445
|
+
}
|
|
446
|
+
get schemas() {
|
|
447
|
+
return this.schema.schemas;
|
|
448
|
+
}
|
|
443
449
|
// 静态方法:创建模型(需要外部传入 client)
|
|
444
450
|
static create(definition, client) {
|
|
445
451
|
const schema = new TableSchema(definition);
|
|
@@ -575,13 +581,46 @@ var Model = class _Model {
|
|
|
575
581
|
syncQueries.push(queryHelper.dropColumns(this.schema, deletedFields));
|
|
576
582
|
}
|
|
577
583
|
if (updatedFields.length > 0) {
|
|
578
|
-
|
|
584
|
+
const fieldDetails = updatedFields.map((field) => {
|
|
585
|
+
const existingType = tableMetadata2.find((t) => t.column_name === field)?.type || "unknown";
|
|
586
|
+
const newType = convertZodToCassandraType(
|
|
587
|
+
this.schema.fields.shape[field]
|
|
588
|
+
);
|
|
589
|
+
return `${field}(${existingType} -> ${newType})`;
|
|
590
|
+
}).join(", ");
|
|
591
|
+
errorReason = `\u5B57\u6BB5\u7C7B\u578B\u6709\u66F4\u65B0\uFF0C\u65E0\u6CD5\u81EA\u52A8\u66F4\u65B0\u3002\u53D8\u66F4\u5B57\u6BB5: ${fieldDetails}`;
|
|
579
592
|
}
|
|
580
593
|
if (hasKeyFieldChanged(this.schema, newFields, deletedFields)) {
|
|
581
|
-
|
|
594
|
+
const partitionKeyFields = this.schema.partitionKeyFields;
|
|
595
|
+
const clusteringKeyFields = this.schema.clusteringKeyFields.map(
|
|
596
|
+
(ck) => ck.field
|
|
597
|
+
);
|
|
598
|
+
const keyFields = [...partitionKeyFields, ...clusteringKeyFields];
|
|
599
|
+
const newKeyFields = newFields.filter(
|
|
600
|
+
(field) => keyFields.includes(field)
|
|
601
|
+
);
|
|
602
|
+
const deletedKeyFields = deletedFields.filter(
|
|
603
|
+
(field) => keyFields.includes(field)
|
|
604
|
+
);
|
|
605
|
+
let keyChangeDetails = [];
|
|
606
|
+
if (newKeyFields.length > 0) {
|
|
607
|
+
keyChangeDetails.push(`\u65B0\u589E\u952E\u5B57\u6BB5: ${newKeyFields.join(", ")}`);
|
|
608
|
+
}
|
|
609
|
+
if (deletedKeyFields.length > 0) {
|
|
610
|
+
keyChangeDetails.push(`\u5220\u9664\u952E\u5B57\u6BB5: ${deletedKeyFields.join(", ")}`);
|
|
611
|
+
}
|
|
612
|
+
errorReason = `\u952E\u5B57\u6BB5\u53D1\u751F\u53D8\u66F4\uFF0C\u65E0\u6CD5\u81EA\u52A8\u66F4\u65B0\u3002${keyChangeDetails.join(
|
|
613
|
+
"; "
|
|
614
|
+
)}`;
|
|
582
615
|
}
|
|
583
616
|
if (isClusteringKeyChanged(this.schema, tableMetadata2)) {
|
|
584
|
-
|
|
617
|
+
const existingClusteringKeys = tableMetadata2.filter((t) => t.kind === "clustering").map((t) => t.column_name);
|
|
618
|
+
const currentClusteringKeys = this.schema.clusteringKeyFields.map(
|
|
619
|
+
(ck) => ck.field
|
|
620
|
+
);
|
|
621
|
+
const existingOrder = existingClusteringKeys.join(", ");
|
|
622
|
+
const currentOrder = currentClusteringKeys.join(", ");
|
|
623
|
+
errorReason = `\u805A\u7C7B\u952E\u914D\u7F6E\u53D1\u751F\u53D8\u5316\uFF0C\u65E0\u6CD5\u81EA\u52A8\u66F4\u65B0\u3002\u73B0\u6709\u987A\u5E8F: [${existingOrder}]\uFF0C\u65B0\u987A\u5E8F: [${currentOrder}]`;
|
|
585
624
|
}
|
|
586
625
|
}
|
|
587
626
|
if (errorReason) {
|
|
@@ -611,7 +650,7 @@ var uuid = () => types.Uuid.random().toString();
|
|
|
611
650
|
var Client = class {
|
|
612
651
|
constructor(options) {
|
|
613
652
|
this.options = options;
|
|
614
|
-
this.cassandraClient = new Client$1(options);
|
|
653
|
+
this.cassandraClient = new Client$1({ ...options });
|
|
615
654
|
}
|
|
616
655
|
cassandraClient;
|
|
617
656
|
models = [];
|
|
@@ -661,7 +700,11 @@ var Client = class {
|
|
|
661
700
|
}
|
|
662
701
|
}
|
|
663
702
|
try {
|
|
664
|
-
const result = await this.cassandraClient.execute(
|
|
703
|
+
const result = await this.cassandraClient.execute(
|
|
704
|
+
cql,
|
|
705
|
+
params,
|
|
706
|
+
executeOptions
|
|
707
|
+
);
|
|
665
708
|
if (this.options.debug) {
|
|
666
709
|
console.log({ query: cql, params, rows: result.rows });
|
|
667
710
|
}
|