@asla/yoursql 0.1.0 → 0.1.2

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.d.ts CHANGED
@@ -4,4 +4,5 @@ export * from "./select/type.ts";
4
4
  export * from "./select/select.ts";
5
5
  export * from "./select/selectable.ts";
6
6
  export * from "./select/TableQuery.ts";
7
+ export * from "./util.ts";
7
8
  //# sourceMappingURL=mod.d.ts.map
package/dist/mod.js CHANGED
@@ -33,6 +33,28 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
33
33
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
34
34
  };
35
35
 
36
+ /**
37
+ * @public
38
+ * @param keepUndefinedKey - 是否保留值为 undefined 的 key
39
+ */
40
+ function getObjectListKeys(objectList, keepUndefinedKey) {
41
+ let keys = new Set();
42
+ for (let i = 0; i < objectList.length; i++) {
43
+ let obj = objectList[i];
44
+ let hasKeys = Object.keys(obj);
45
+ let k;
46
+ for (let j = 0; j < hasKeys.length; j++) {
47
+ k = hasKeys[j];
48
+ if (typeof k !== "string")
49
+ continue;
50
+ if (!keepUndefinedKey && obj[k] === undefined)
51
+ continue;
52
+ keys.add(k);
53
+ }
54
+ }
55
+ return Array.from(keys);
56
+ }
57
+
36
58
  var _SqlRaw_value;
37
59
  /**
38
60
  * SQL 原始字符对象
@@ -147,7 +169,7 @@ class SqlValuesCreator {
147
169
  rows = [];
148
170
  j = 0;
149
171
  for (; j < keys.length; j++) {
150
- value = object[keys[j]] ?? null;
172
+ value = object[keys[j]];
151
173
  rows[j] = this.toSqlStr(value);
152
174
  }
153
175
  str += ",\n(" + rows.join(",") + ")";
@@ -205,25 +227,6 @@ function toKeyType(object, keys_types) {
205
227
  }
206
228
  return { type, keys };
207
229
  }
208
- /**
209
- * @public
210
- * @param keepUndefinedKey - 是否保留值为 undefined 的 key
211
- */
212
- function getObjectListKeys(objectList, keepUndefinedKey) {
213
- let keys = new Set();
214
- for (let i = 0; i < objectList.length; i++) {
215
- let obj = objectList[i];
216
- let hasKeys = Object.keys(obj);
217
- let k;
218
- for (let j = 0; j < hasKeys.length; j++) {
219
- k = hasKeys[j];
220
- if ((!keepUndefinedKey && obj[k] === undefined) || typeof k !== "string")
221
- continue;
222
- keys.add(k);
223
- }
224
- }
225
- return Array.from(keys);
226
- }
227
230
 
228
231
  /** @public PgSql 转换器 */
229
232
  const pgSqlTransformer = new Map([
@@ -601,7 +604,7 @@ class DbTableQuery extends DbTable {
601
604
  if (values instanceof Array) {
602
605
  if (values.length === 0)
603
606
  throw new Error("值不能为空");
604
- insertCol = Object.keys(values[0]);
607
+ insertCol = getObjectListKeys(values);
605
608
  valuesStr = `VALUES\n${this.statement.objectListToValuesList(values, insertCol)}`;
606
609
  }
607
610
  else if (values instanceof SqlQueryStatement) {
@@ -66,10 +66,5 @@ export declare class SqlValuesCreator {
66
66
  */
67
67
  toValues(values: readonly any[]): string;
68
68
  }
69
- /**
70
- * @public
71
- * @param keepUndefinedKey - 是否保留值为 undefined 的 key
72
- */
73
- export declare function getObjectListKeys(objectList: any[], keepUndefinedKey?: boolean): string[];
74
69
  export {};
75
70
  //# sourceMappingURL=sql_value.d.ts.map
package/dist/util.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @public
3
+ * @param keepUndefinedKey - 是否保留值为 undefined 的 key
4
+ */
5
+ export declare function getObjectListKeys(objectList: any[], keepUndefinedKey?: boolean): string[];
6
+ //# sourceMappingURL=util.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asla/yoursql",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "types": "./dist/mod.d.ts",