imean-cassandra-orm 3.0.1 → 3.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/dist/mod.cjs +29 -14
- package/dist/mod.js +29 -14
- package/package.json +1 -1
package/dist/mod.cjs
CHANGED
|
@@ -1527,10 +1527,12 @@ var Model = class _Model {
|
|
|
1527
1527
|
// 同步 Schema
|
|
1528
1528
|
async syncSchema(force = false) {
|
|
1529
1529
|
try {
|
|
1530
|
+
console.log(`\u{1F504} \u5F00\u59CB\u540C\u6B65\u8868: ${this.schema.keyspace}.${this.schema.tableName}`);
|
|
1530
1531
|
const operations = await this.syncTableSchema(force);
|
|
1532
|
+
console.log(`\u2705 \u8868 ${this.schema.keyspace}.${this.schema.tableName} \u540C\u6B65\u5B8C\u6210`);
|
|
1531
1533
|
return operations.join("\n");
|
|
1532
1534
|
} catch (error) {
|
|
1533
|
-
console.error(
|
|
1535
|
+
console.error(`\u274C \u8868 ${this.schema.keyspace}.${this.schema.tableName} \u540C\u6B65\u5931\u8D25:`, error);
|
|
1534
1536
|
throw error;
|
|
1535
1537
|
}
|
|
1536
1538
|
}
|
|
@@ -1538,6 +1540,12 @@ var Model = class _Model {
|
|
|
1538
1540
|
async syncTableSchema(forceRecreate = false) {
|
|
1539
1541
|
const operations = [];
|
|
1540
1542
|
try {
|
|
1543
|
+
console.log(` \u{1F4CB} \u8868\u7ED3\u6784: ${this.schema.keyspace}.${this.schema.tableName}`);
|
|
1544
|
+
console.log(` \u{1F511} \u5206\u533A\u952E: [${this.schema.partitionKey.join(", ")}]`);
|
|
1545
|
+
if (this.schema.clusteringKey) {
|
|
1546
|
+
console.log(` \u{1F4CA} \u805A\u7C7B\u952E: ${Object.entries(this.schema.clusteringKey).map(([k, v]) => `${k}:${v}`).join(", ")}`);
|
|
1547
|
+
}
|
|
1548
|
+
console.log(` \u{1F4DD} \u5B57\u6BB5\u6570\u91CF: ${Object.keys(this.schema.fields.shape).length}`);
|
|
1541
1549
|
await this.client.execute(
|
|
1542
1550
|
queryHelper.ensureKeyspace(
|
|
1543
1551
|
this.schema.keyspace,
|
|
@@ -1571,7 +1579,7 @@ var Model = class _Model {
|
|
|
1571
1579
|
} else if (!forceRecreate && hasUnalterableChanges) {
|
|
1572
1580
|
const reasons = tableChanges.unalterableReasons.join("; ");
|
|
1573
1581
|
throw new Error(
|
|
1574
|
-
`\u8868\u7ED3\u6784\u5B58\u5728\u4E0D\u53EF\u53D8\u66F4\u7684\u4FEE\u6539\uFF0C\u9700\u8981\u4F7F\u7528 forceRecreate=true \u6765\u91CD\u5EFA\u8868\u3002
|
|
1582
|
+
`\u8868 ${this.schema.keyspace}.${this.schema.tableName} \u7ED3\u6784\u5B58\u5728\u4E0D\u53EF\u53D8\u66F4\u7684\u4FEE\u6539\uFF0C\u9700\u8981\u4F7F\u7528 forceRecreate=true \u6765\u91CD\u5EFA\u8868\u3002
|
|
1575
1583
|
\u4E0D\u53EF\u53D8\u66F4\u7684\u4FEE\u6539\u5305\u62EC\uFF1A
|
|
1576
1584
|
${reasons}
|
|
1577
1585
|
\u5176\u4ED6\u53D8\u66F4\uFF1A${tableChanges.changes.join("; ")}`
|
|
@@ -1654,7 +1662,7 @@ ${reasons}
|
|
|
1654
1662
|
operations.push(...indexOperations);
|
|
1655
1663
|
return { operations, changes, unalterableReasons };
|
|
1656
1664
|
} catch (error) {
|
|
1657
|
-
throw new Error(`\u5206\u6790\u8868\u7ED3\u6784\u53D8\u66F4\u5931\u8D25: ${error}`);
|
|
1665
|
+
throw new Error(`\u5206\u6790\u8868 ${this.schema.keyspace}.${this.schema.tableName} \u7ED3\u6784\u53D8\u66F4\u5931\u8D25: ${error}`);
|
|
1658
1666
|
}
|
|
1659
1667
|
}
|
|
1660
1668
|
// 智能同步索引
|
|
@@ -1751,7 +1759,10 @@ ${reasons}
|
|
|
1751
1759
|
);
|
|
1752
1760
|
const existingType = existingField.type.toLowerCase();
|
|
1753
1761
|
if (!this.isTypeCompatible(existingType, schemaType)) {
|
|
1754
|
-
return {
|
|
1762
|
+
return {
|
|
1763
|
+
hasChanges: true,
|
|
1764
|
+
reasons: [`\u5B57\u6BB5\u7C7B\u578B\u4E0D\u517C\u5BB9: ${field} (${existingType} \u2192 ${schemaType})`]
|
|
1765
|
+
};
|
|
1755
1766
|
}
|
|
1756
1767
|
}
|
|
1757
1768
|
}
|
|
@@ -1763,25 +1774,29 @@ ${reasons}
|
|
|
1763
1774
|
}
|
|
1764
1775
|
// 获取 Cassandra 类型
|
|
1765
1776
|
getCassandraType(zodType) {
|
|
1766
|
-
|
|
1767
|
-
|
|
1777
|
+
let baseType = zodType;
|
|
1778
|
+
while (baseType._def && (baseType._def.typeName === "ZodOptional" || baseType._def.typeName === "ZodNullable" || baseType._def.typeName === "ZodDefault")) {
|
|
1779
|
+
baseType = baseType._def.innerType;
|
|
1780
|
+
}
|
|
1781
|
+
if (baseType._cassandraType) {
|
|
1782
|
+
return baseType._cassandraType;
|
|
1768
1783
|
}
|
|
1769
|
-
if (
|
|
1770
|
-
if (
|
|
1784
|
+
if (baseType._def.typeName === "ZodString") {
|
|
1785
|
+
if (baseType._def.checks && baseType._def.checks.some((c) => c.kind === "uuid")) {
|
|
1771
1786
|
return "uuid";
|
|
1772
1787
|
}
|
|
1773
1788
|
return "text";
|
|
1774
|
-
} else if (
|
|
1789
|
+
} else if (baseType._def.typeName === "ZodNumber") {
|
|
1775
1790
|
return "double";
|
|
1776
|
-
} else if (
|
|
1791
|
+
} else if (baseType._def.typeName === "ZodBoolean") {
|
|
1777
1792
|
return "boolean";
|
|
1778
|
-
} else if (
|
|
1793
|
+
} else if (baseType._def.typeName === "ZodDate") {
|
|
1779
1794
|
return "timestamp";
|
|
1780
|
-
} else if (
|
|
1795
|
+
} else if (baseType._def.typeName === "ZodArray") {
|
|
1781
1796
|
return "list";
|
|
1782
|
-
} else if (
|
|
1797
|
+
} else if (baseType._def.typeName === "ZodSet") {
|
|
1783
1798
|
return "set";
|
|
1784
|
-
} else if (
|
|
1799
|
+
} else if (baseType._def.typeName === "ZodRecord") {
|
|
1785
1800
|
return "map";
|
|
1786
1801
|
}
|
|
1787
1802
|
return "text";
|
package/dist/mod.js
CHANGED
|
@@ -1525,10 +1525,12 @@ var Model = class _Model {
|
|
|
1525
1525
|
// 同步 Schema
|
|
1526
1526
|
async syncSchema(force = false) {
|
|
1527
1527
|
try {
|
|
1528
|
+
console.log(`\u{1F504} \u5F00\u59CB\u540C\u6B65\u8868: ${this.schema.keyspace}.${this.schema.tableName}`);
|
|
1528
1529
|
const operations = await this.syncTableSchema(force);
|
|
1530
|
+
console.log(`\u2705 \u8868 ${this.schema.keyspace}.${this.schema.tableName} \u540C\u6B65\u5B8C\u6210`);
|
|
1529
1531
|
return operations.join("\n");
|
|
1530
1532
|
} catch (error) {
|
|
1531
|
-
console.error(
|
|
1533
|
+
console.error(`\u274C \u8868 ${this.schema.keyspace}.${this.schema.tableName} \u540C\u6B65\u5931\u8D25:`, error);
|
|
1532
1534
|
throw error;
|
|
1533
1535
|
}
|
|
1534
1536
|
}
|
|
@@ -1536,6 +1538,12 @@ var Model = class _Model {
|
|
|
1536
1538
|
async syncTableSchema(forceRecreate = false) {
|
|
1537
1539
|
const operations = [];
|
|
1538
1540
|
try {
|
|
1541
|
+
console.log(` \u{1F4CB} \u8868\u7ED3\u6784: ${this.schema.keyspace}.${this.schema.tableName}`);
|
|
1542
|
+
console.log(` \u{1F511} \u5206\u533A\u952E: [${this.schema.partitionKey.join(", ")}]`);
|
|
1543
|
+
if (this.schema.clusteringKey) {
|
|
1544
|
+
console.log(` \u{1F4CA} \u805A\u7C7B\u952E: ${Object.entries(this.schema.clusteringKey).map(([k, v]) => `${k}:${v}`).join(", ")}`);
|
|
1545
|
+
}
|
|
1546
|
+
console.log(` \u{1F4DD} \u5B57\u6BB5\u6570\u91CF: ${Object.keys(this.schema.fields.shape).length}`);
|
|
1539
1547
|
await this.client.execute(
|
|
1540
1548
|
queryHelper.ensureKeyspace(
|
|
1541
1549
|
this.schema.keyspace,
|
|
@@ -1569,7 +1577,7 @@ var Model = class _Model {
|
|
|
1569
1577
|
} else if (!forceRecreate && hasUnalterableChanges) {
|
|
1570
1578
|
const reasons = tableChanges.unalterableReasons.join("; ");
|
|
1571
1579
|
throw new Error(
|
|
1572
|
-
`\u8868\u7ED3\u6784\u5B58\u5728\u4E0D\u53EF\u53D8\u66F4\u7684\u4FEE\u6539\uFF0C\u9700\u8981\u4F7F\u7528 forceRecreate=true \u6765\u91CD\u5EFA\u8868\u3002
|
|
1580
|
+
`\u8868 ${this.schema.keyspace}.${this.schema.tableName} \u7ED3\u6784\u5B58\u5728\u4E0D\u53EF\u53D8\u66F4\u7684\u4FEE\u6539\uFF0C\u9700\u8981\u4F7F\u7528 forceRecreate=true \u6765\u91CD\u5EFA\u8868\u3002
|
|
1573
1581
|
\u4E0D\u53EF\u53D8\u66F4\u7684\u4FEE\u6539\u5305\u62EC\uFF1A
|
|
1574
1582
|
${reasons}
|
|
1575
1583
|
\u5176\u4ED6\u53D8\u66F4\uFF1A${tableChanges.changes.join("; ")}`
|
|
@@ -1652,7 +1660,7 @@ ${reasons}
|
|
|
1652
1660
|
operations.push(...indexOperations);
|
|
1653
1661
|
return { operations, changes, unalterableReasons };
|
|
1654
1662
|
} catch (error) {
|
|
1655
|
-
throw new Error(`\u5206\u6790\u8868\u7ED3\u6784\u53D8\u66F4\u5931\u8D25: ${error}`);
|
|
1663
|
+
throw new Error(`\u5206\u6790\u8868 ${this.schema.keyspace}.${this.schema.tableName} \u7ED3\u6784\u53D8\u66F4\u5931\u8D25: ${error}`);
|
|
1656
1664
|
}
|
|
1657
1665
|
}
|
|
1658
1666
|
// 智能同步索引
|
|
@@ -1749,7 +1757,10 @@ ${reasons}
|
|
|
1749
1757
|
);
|
|
1750
1758
|
const existingType = existingField.type.toLowerCase();
|
|
1751
1759
|
if (!this.isTypeCompatible(existingType, schemaType)) {
|
|
1752
|
-
return {
|
|
1760
|
+
return {
|
|
1761
|
+
hasChanges: true,
|
|
1762
|
+
reasons: [`\u5B57\u6BB5\u7C7B\u578B\u4E0D\u517C\u5BB9: ${field} (${existingType} \u2192 ${schemaType})`]
|
|
1763
|
+
};
|
|
1753
1764
|
}
|
|
1754
1765
|
}
|
|
1755
1766
|
}
|
|
@@ -1761,25 +1772,29 @@ ${reasons}
|
|
|
1761
1772
|
}
|
|
1762
1773
|
// 获取 Cassandra 类型
|
|
1763
1774
|
getCassandraType(zodType) {
|
|
1764
|
-
|
|
1765
|
-
|
|
1775
|
+
let baseType = zodType;
|
|
1776
|
+
while (baseType._def && (baseType._def.typeName === "ZodOptional" || baseType._def.typeName === "ZodNullable" || baseType._def.typeName === "ZodDefault")) {
|
|
1777
|
+
baseType = baseType._def.innerType;
|
|
1778
|
+
}
|
|
1779
|
+
if (baseType._cassandraType) {
|
|
1780
|
+
return baseType._cassandraType;
|
|
1766
1781
|
}
|
|
1767
|
-
if (
|
|
1768
|
-
if (
|
|
1782
|
+
if (baseType._def.typeName === "ZodString") {
|
|
1783
|
+
if (baseType._def.checks && baseType._def.checks.some((c) => c.kind === "uuid")) {
|
|
1769
1784
|
return "uuid";
|
|
1770
1785
|
}
|
|
1771
1786
|
return "text";
|
|
1772
|
-
} else if (
|
|
1787
|
+
} else if (baseType._def.typeName === "ZodNumber") {
|
|
1773
1788
|
return "double";
|
|
1774
|
-
} else if (
|
|
1789
|
+
} else if (baseType._def.typeName === "ZodBoolean") {
|
|
1775
1790
|
return "boolean";
|
|
1776
|
-
} else if (
|
|
1791
|
+
} else if (baseType._def.typeName === "ZodDate") {
|
|
1777
1792
|
return "timestamp";
|
|
1778
|
-
} else if (
|
|
1793
|
+
} else if (baseType._def.typeName === "ZodArray") {
|
|
1779
1794
|
return "list";
|
|
1780
|
-
} else if (
|
|
1795
|
+
} else if (baseType._def.typeName === "ZodSet") {
|
|
1781
1796
|
return "set";
|
|
1782
|
-
} else if (
|
|
1797
|
+
} else if (baseType._def.typeName === "ZodRecord") {
|
|
1783
1798
|
return "map";
|
|
1784
1799
|
}
|
|
1785
1800
|
return "text";
|