tinybase 10.0.0-beta.0 → 10.0.0-beta.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.
Files changed (185) hide show
  1. package/@types/common/index.d.ts +1 -0
  2. package/@types/common/with-schemas/index.d.ts +1 -0
  3. package/@types/indexes/index.d.ts +4 -3
  4. package/@types/indexes/with-schemas/index.d.ts +4 -3
  5. package/@types/metrics/index.d.ts +1 -0
  6. package/@types/metrics/with-schemas/index.d.ts +1 -0
  7. package/@types/omni/index.d.ts +1 -0
  8. package/@types/omni/with-schemas/index.d.ts +1 -0
  9. package/@types/persisters/index.d.ts +1 -0
  10. package/@types/persisters/persister-partykit-server/index.d.ts +17 -0
  11. package/@types/persisters/persister-partykit-server/with-schemas/index.d.ts +17 -0
  12. package/@types/persisters/persister-tinyjoin/index.d.ts +197 -0
  13. package/@types/persisters/persister-tinyjoin/with-schemas/index.d.ts +221 -0
  14. package/@types/persisters/with-schemas/index.d.ts +1 -0
  15. package/@types/queries/index.d.ts +3 -0
  16. package/@types/queries/with-schemas/index.d.ts +3 -0
  17. package/@types/relationships/index.d.ts +1 -0
  18. package/@types/relationships/with-schemas/index.d.ts +1 -0
  19. package/@types/store/index.d.ts +4 -0
  20. package/@types/store/with-schemas/index.d.ts +4 -0
  21. package/@types/ui-react/index.d.ts +2 -0
  22. package/@types/ui-react/with-schemas/index.d.ts +1 -0
  23. package/@types/ui-react-dom-charts/index.d.ts +7 -0
  24. package/@types/ui-react-dom-charts/with-schemas/index.d.ts +7 -0
  25. package/@types/ui-solid/index.d.ts +2 -0
  26. package/@types/ui-solid/with-schemas/index.d.ts +1 -0
  27. package/@types/ui-svelte/index.d.ts +23 -0
  28. package/@types/ui-svelte/with-schemas/index.d.ts +23 -0
  29. package/@types/ui-svelte-dom/index.d.ts +10 -0
  30. package/@types/ui-svelte-dom/with-schemas/index.d.ts +10 -0
  31. package/@types/ui-svelte-inspector/index.d.ts +1 -0
  32. package/@types/ui-svelte-inspector/with-schemas/index.d.ts +1 -0
  33. package/checkpoints/index.js +4 -2
  34. package/checkpoints/with-schemas/index.js +4 -2
  35. package/index.js +37 -4
  36. package/metrics/index.js +2 -1
  37. package/metrics/with-schemas/index.js +2 -1
  38. package/min/checkpoints/index.js +1 -1
  39. package/min/checkpoints/index.js.gz +0 -0
  40. package/min/checkpoints/with-schemas/index.js +1 -1
  41. package/min/checkpoints/with-schemas/index.js.gz +0 -0
  42. package/min/index.js +1 -1
  43. package/min/index.js.gz +0 -0
  44. package/min/metrics/index.js +1 -1
  45. package/min/metrics/index.js.gz +0 -0
  46. package/min/metrics/with-schemas/index.js +1 -1
  47. package/min/metrics/with-schemas/index.js.gz +0 -0
  48. package/min/omni/index.js +1 -1
  49. package/min/omni/index.js.gz +0 -0
  50. package/min/omni/with-schemas/index.js +1 -1
  51. package/min/omni/with-schemas/index.js.gz +0 -0
  52. package/min/persisters/index.js +1 -1
  53. package/min/persisters/index.js.gz +0 -0
  54. package/min/persisters/persister-better-sqlite3/index.js +1 -1
  55. package/min/persisters/persister-better-sqlite3/index.js.gz +0 -0
  56. package/min/persisters/persister-better-sqlite3/with-schemas/index.js +1 -1
  57. package/min/persisters/persister-better-sqlite3/with-schemas/index.js.gz +0 -0
  58. package/min/persisters/persister-capacitor-sqlite/index.js +1 -1
  59. package/min/persisters/persister-capacitor-sqlite/index.js.gz +0 -0
  60. package/min/persisters/persister-capacitor-sqlite/with-schemas/index.js +1 -1
  61. package/min/persisters/persister-capacitor-sqlite/with-schemas/index.js.gz +0 -0
  62. package/min/persisters/persister-cr-sqlite-wasm/index.js +1 -1
  63. package/min/persisters/persister-cr-sqlite-wasm/index.js.gz +0 -0
  64. package/min/persisters/persister-cr-sqlite-wasm/with-schemas/index.js +1 -1
  65. package/min/persisters/persister-cr-sqlite-wasm/with-schemas/index.js.gz +0 -0
  66. package/min/persisters/persister-durable-object-sql-storage/index.js +1 -1
  67. package/min/persisters/persister-durable-object-sql-storage/index.js.gz +0 -0
  68. package/min/persisters/persister-durable-object-sql-storage/with-schemas/index.js +1 -1
  69. package/min/persisters/persister-durable-object-sql-storage/with-schemas/index.js.gz +0 -0
  70. package/min/persisters/persister-electric-sql/index.js +1 -1
  71. package/min/persisters/persister-electric-sql/index.js.gz +0 -0
  72. package/min/persisters/persister-electric-sql/with-schemas/index.js +1 -1
  73. package/min/persisters/persister-electric-sql/with-schemas/index.js.gz +0 -0
  74. package/min/persisters/persister-expo-sqlite/index.js +1 -1
  75. package/min/persisters/persister-expo-sqlite/index.js.gz +0 -0
  76. package/min/persisters/persister-expo-sqlite/with-schemas/index.js +1 -1
  77. package/min/persisters/persister-expo-sqlite/with-schemas/index.js.gz +0 -0
  78. package/min/persisters/persister-libsql/index.js +1 -1
  79. package/min/persisters/persister-libsql/index.js.gz +0 -0
  80. package/min/persisters/persister-libsql/with-schemas/index.js +1 -1
  81. package/min/persisters/persister-libsql/with-schemas/index.js.gz +0 -0
  82. package/min/persisters/persister-pg/index.js +1 -1
  83. package/min/persisters/persister-pg/index.js.gz +0 -0
  84. package/min/persisters/persister-pg/with-schemas/index.js +1 -1
  85. package/min/persisters/persister-pg/with-schemas/index.js.gz +0 -0
  86. package/min/persisters/persister-pglite/index.js +1 -1
  87. package/min/persisters/persister-pglite/index.js.gz +0 -0
  88. package/min/persisters/persister-pglite/with-schemas/index.js +1 -1
  89. package/min/persisters/persister-pglite/with-schemas/index.js.gz +0 -0
  90. package/min/persisters/persister-postgres/index.js +1 -1
  91. package/min/persisters/persister-postgres/index.js.gz +0 -0
  92. package/min/persisters/persister-postgres/with-schemas/index.js +1 -1
  93. package/min/persisters/persister-postgres/with-schemas/index.js.gz +0 -0
  94. package/min/persisters/persister-powersync/index.js +1 -1
  95. package/min/persisters/persister-powersync/index.js.gz +0 -0
  96. package/min/persisters/persister-powersync/with-schemas/index.js +1 -1
  97. package/min/persisters/persister-powersync/with-schemas/index.js.gz +0 -0
  98. package/min/persisters/persister-react-native-sqlite/index.js +1 -1
  99. package/min/persisters/persister-react-native-sqlite/index.js.gz +0 -0
  100. package/min/persisters/persister-react-native-sqlite/with-schemas/index.js +1 -1
  101. package/min/persisters/persister-react-native-sqlite/with-schemas/index.js.gz +0 -0
  102. package/min/persisters/persister-sqlite-bun/index.js +1 -1
  103. package/min/persisters/persister-sqlite-bun/index.js.gz +0 -0
  104. package/min/persisters/persister-sqlite-bun/with-schemas/index.js +1 -1
  105. package/min/persisters/persister-sqlite-bun/with-schemas/index.js.gz +0 -0
  106. package/min/persisters/persister-sqlite-node/index.js +1 -1
  107. package/min/persisters/persister-sqlite-node/index.js.gz +0 -0
  108. package/min/persisters/persister-sqlite-node/with-schemas/index.js +1 -1
  109. package/min/persisters/persister-sqlite-node/with-schemas/index.js.gz +0 -0
  110. package/min/persisters/persister-sqlite-wasm/index.js +1 -1
  111. package/min/persisters/persister-sqlite-wasm/index.js.gz +0 -0
  112. package/min/persisters/persister-sqlite-wasm/with-schemas/index.js +1 -1
  113. package/min/persisters/persister-sqlite-wasm/with-schemas/index.js.gz +0 -0
  114. package/min/persisters/persister-sqlite3/index.js +1 -1
  115. package/min/persisters/persister-sqlite3/index.js.gz +0 -0
  116. package/min/persisters/persister-sqlite3/with-schemas/index.js +1 -1
  117. package/min/persisters/persister-sqlite3/with-schemas/index.js.gz +0 -0
  118. package/min/persisters/persister-tinyjoin/index.js +1 -0
  119. package/min/persisters/persister-tinyjoin/index.js.gz +0 -0
  120. package/min/persisters/persister-tinyjoin/with-schemas/index.js +1 -0
  121. package/min/persisters/persister-tinyjoin/with-schemas/index.js.gz +0 -0
  122. package/min/persisters/with-schemas/index.js +1 -1
  123. package/min/persisters/with-schemas/index.js.gz +0 -0
  124. package/min/queries/index.js +1 -1
  125. package/min/queries/index.js.gz +0 -0
  126. package/min/queries/with-schemas/index.js +1 -1
  127. package/min/queries/with-schemas/index.js.gz +0 -0
  128. package/min/relationships/index.js +1 -1
  129. package/min/relationships/index.js.gz +0 -0
  130. package/min/relationships/with-schemas/index.js +1 -1
  131. package/min/relationships/with-schemas/index.js.gz +0 -0
  132. package/min/synchronizers/synchronizer-local/index.js +1 -1
  133. package/min/synchronizers/synchronizer-local/index.js.gz +0 -0
  134. package/min/synchronizers/synchronizer-local/with-schemas/index.js +1 -1
  135. package/min/synchronizers/synchronizer-local/with-schemas/index.js.gz +0 -0
  136. package/min/with-schemas/index.js +1 -1
  137. package/min/with-schemas/index.js.gz +0 -0
  138. package/omni/index.js +205 -94
  139. package/omni/with-schemas/index.js +205 -94
  140. package/package.json +54 -14
  141. package/persisters/index.js +28 -13
  142. package/persisters/persister-better-sqlite3/index.js +70 -55
  143. package/persisters/persister-better-sqlite3/with-schemas/index.js +70 -55
  144. package/persisters/persister-capacitor-sqlite/index.js +70 -55
  145. package/persisters/persister-capacitor-sqlite/with-schemas/index.js +70 -55
  146. package/persisters/persister-cr-sqlite-wasm/index.js +70 -55
  147. package/persisters/persister-cr-sqlite-wasm/with-schemas/index.js +70 -55
  148. package/persisters/persister-durable-object-sql-storage/index.js +28 -13
  149. package/persisters/persister-durable-object-sql-storage/with-schemas/index.js +28 -13
  150. package/persisters/persister-electric-sql/index.js +70 -55
  151. package/persisters/persister-electric-sql/with-schemas/index.js +70 -55
  152. package/persisters/persister-expo-sqlite/index.js +70 -55
  153. package/persisters/persister-expo-sqlite/with-schemas/index.js +70 -55
  154. package/persisters/persister-libsql/index.js +91 -78
  155. package/persisters/persister-libsql/with-schemas/index.js +91 -78
  156. package/persisters/persister-pg/index.js +77 -62
  157. package/persisters/persister-pg/with-schemas/index.js +77 -62
  158. package/persisters/persister-pglite/index.js +28 -13
  159. package/persisters/persister-pglite/with-schemas/index.js +28 -13
  160. package/persisters/persister-postgres/index.js +28 -13
  161. package/persisters/persister-postgres/with-schemas/index.js +28 -13
  162. package/persisters/persister-powersync/index.js +81 -66
  163. package/persisters/persister-powersync/with-schemas/index.js +81 -66
  164. package/persisters/persister-react-native-sqlite/index.js +70 -55
  165. package/persisters/persister-react-native-sqlite/with-schemas/index.js +70 -55
  166. package/persisters/persister-sqlite-bun/index.js +70 -55
  167. package/persisters/persister-sqlite-bun/with-schemas/index.js +70 -55
  168. package/persisters/persister-sqlite-node/index.js +70 -55
  169. package/persisters/persister-sqlite-node/with-schemas/index.js +70 -55
  170. package/persisters/persister-sqlite-wasm/index.js +70 -55
  171. package/persisters/persister-sqlite-wasm/with-schemas/index.js +70 -55
  172. package/persisters/persister-sqlite3/index.js +70 -55
  173. package/persisters/persister-sqlite3/with-schemas/index.js +70 -55
  174. package/persisters/persister-tinyjoin/index.js +1710 -0
  175. package/persisters/persister-tinyjoin/with-schemas/index.js +1710 -0
  176. package/persisters/with-schemas/index.js +28 -13
  177. package/queries/index.js +2 -1
  178. package/queries/with-schemas/index.js +2 -1
  179. package/readme.md +3 -3
  180. package/relationships/index.js +39 -9
  181. package/relationships/with-schemas/index.js +39 -9
  182. package/releases.md +20 -1
  183. package/synchronizers/synchronizer-local/index.js +1 -1
  184. package/synchronizers/synchronizer-local/with-schemas/index.js +1 -1
  185. package/with-schemas/index.js +37 -4
@@ -92,57 +92,6 @@ const arrayClear = (array, to = size(array)) => array.splice(0, to);
92
92
  const arrayPush = (array, ...values) => array.push(...values);
93
93
  const arrayShift = (array) => array.shift();
94
94
 
95
- const SINGLE_ROW_ID = '_';
96
- const DEFAULT_ROW_ID_COLUMN_NAME = '_id';
97
- const SELECT = 'SELECT';
98
- const WHERE = 'WHERE';
99
- const TABLE = 'TABLE';
100
- const INSERT = 'INSERT';
101
- const DELETE = 'DELETE';
102
- const UPDATE = 'UPDATE';
103
- const ALTER_TABLE = 'ALTER ' + TABLE;
104
- const FROM = 'FROM';
105
- const DELETE_FROM = DELETE + ' ' + FROM;
106
- const SELECT_STAR_FROM = SELECT + '*' + FROM;
107
- const CREATE = 'CREATE ';
108
- const CREATE_TABLE = CREATE + TABLE;
109
- const OR_REPLACE = 'OR REPLACE ';
110
- const FUNCTION = 'FUNCTION';
111
- const TABLE_NAME_PLACEHOLDER_REGEX = /\$tableName/g;
112
- const getWrappedCommand = (executeCommand, onSqlCommand) =>
113
- onSqlCommand
114
- ? async (sql, params) => {
115
- onSqlCommand(sql, params);
116
- return await executeCommand(sql, params);
117
- }
118
- : executeCommand;
119
- const escapeId = (str) =>
120
- arrayJoin(
121
- arrayMap(strSplit(str, DOT), (part) => `"${strReplace(part, /"/g, '""')}"`),
122
- DOT,
123
- );
124
- const escapeIds = (...ids) => escapeId(arrayJoin(ids, '_'));
125
- const escapeColumnNames = (...columnNames) =>
126
- arrayJoin(arrayMap(columnNames, escapeId), COMMA);
127
- const numberedPlaceholder = (offset) => '$' + offset[0]++;
128
- const getPlaceholders = (array, getPlaceholder, offset = [1]) =>
129
- arrayJoin(
130
- arrayMap(array, () => getPlaceholder(offset)),
131
- COMMA,
132
- );
133
- const getWhereCondition = (tableName, condition = TRUE) =>
134
- WHERE + `(${replaceTableName(condition, escapeId(tableName))})`;
135
- const replaceTableName = (condition, tableName) =>
136
- strReplace(condition, TABLE_NAME_PLACEHOLDER_REGEX, tableName);
137
-
138
- const collSize = (coll) => coll?.size ?? 0;
139
- const collHas = (coll, keyOrValue) => coll?.has(keyOrValue) ?? false;
140
- const collIsEmpty = (coll) => isUndefined(coll) || collSize(coll) == 0;
141
- const collValues = (coll) => [...(coll?.values() ?? [])];
142
- const collClear = (coll) => coll.clear();
143
- const collForEach = (coll, cb) => coll?.forEach(cb);
144
- const collDel = (coll, keyOrValue) => coll?.delete(keyOrValue);
145
-
146
95
  const object = Object;
147
96
  const getPrototypeOf = (obj) => object.getPrototypeOf(obj);
148
97
  const objEntries = object.entries;
@@ -192,6 +141,69 @@ const objValues = (obj) => object.values(obj);
192
141
  const objSize = (obj) => size(objIds(obj));
193
142
  const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
194
143
 
144
+ const SINGLE_ROW_ID = '_';
145
+ const DEFAULT_ROW_ID_COLUMN_NAME = '_id';
146
+ const SELECT = 'SELECT';
147
+ const WHERE = 'WHERE';
148
+ const TABLE = 'TABLE';
149
+ const INSERT = 'INSERT';
150
+ const DELETE = 'DELETE';
151
+ const UPDATE = 'UPDATE';
152
+ const ALTER_TABLE = 'ALTER ' + TABLE;
153
+ const FROM = 'FROM';
154
+ const DELETE_FROM = DELETE + ' ' + FROM;
155
+ const SELECT_STAR_FROM = SELECT + '*' + FROM;
156
+ const CREATE = 'CREATE ';
157
+ const CREATE_TABLE = CREATE + TABLE;
158
+ const OR_REPLACE = 'OR REPLACE ';
159
+ const FUNCTION = 'FUNCTION';
160
+ const TABLE_NAME_PLACEHOLDER_REGEX = /\$tableName/g;
161
+ const getWrappedCommand = (executeCommand, onSqlCommand) =>
162
+ onSqlCommand
163
+ ? async (sql, params) => {
164
+ onSqlCommand(sql, params);
165
+ return await executeCommand(sql, params);
166
+ }
167
+ : executeCommand;
168
+ const escapeId = (str) =>
169
+ arrayJoin(
170
+ arrayMap(strSplit(str, DOT), (part) => `"${strReplace(part, /"/g, '""')}"`),
171
+ DOT,
172
+ );
173
+ const escapeIds = (...ids) => escapeId(arrayJoin(ids, '_'));
174
+ const escapeColumnNames = (...columnNames) =>
175
+ arrayJoin(arrayMap(columnNames, escapeId), COMMA);
176
+ const numberedPlaceholder = (offset) => '$' + offset[0]++;
177
+ const getPlaceholders = (array, getPlaceholder, offset = [1]) =>
178
+ arrayJoin(
179
+ arrayMap(array, () => getPlaceholder(offset)),
180
+ COMMA,
181
+ );
182
+ const getWhere = (tableName, condition = TRUE, extraCondition) => {
183
+ const conditions = arrayFilter(
184
+ [
185
+ condition == TRUE
186
+ ? void 0
187
+ : `(${replaceTableName(condition, escapeId(tableName))})`,
188
+ extraCondition,
189
+ ],
190
+ (condition2) => !isUndefined(condition2),
191
+ );
192
+ return isEmpty(conditions)
193
+ ? EMPTY_STRING
194
+ : WHERE + arrayJoin(conditions, 'AND');
195
+ };
196
+ const replaceTableName = (condition, tableName) =>
197
+ strReplace(condition, TABLE_NAME_PLACEHOLDER_REGEX, tableName);
198
+
199
+ const collSize = (coll) => coll?.size ?? 0;
200
+ const collHas = (coll, keyOrValue) => coll?.has(keyOrValue) ?? false;
201
+ const collIsEmpty = (coll) => isUndefined(coll) || collSize(coll) == 0;
202
+ const collValues = (coll) => [...(coll?.values() ?? [])];
203
+ const collClear = (coll) => coll.clear();
204
+ const collForEach = (coll, cb) => coll?.forEach(cb);
205
+ const collDel = (coll, keyOrValue) => coll?.delete(keyOrValue);
206
+
195
207
  const jsonString = JSON.stringify;
196
208
  const jsonParse = JSON.parse;
197
209
  const jsonStringWithUndefined = (obj) =>
@@ -1039,7 +1051,7 @@ const getCommandFunctions = (
1039
1051
  await executeCommand(
1040
1052
  SELECT_STAR_FROM +
1041
1053
  escapeId(tableName) +
1042
- getWhereCondition(tableName, condition),
1054
+ getWhere(tableName, condition),
1043
1055
  ),
1044
1056
  (row) => {
1045
1057
  const rowId = row[rowIdColumnName];
@@ -1195,9 +1207,7 @@ const getCommandFunctions = (
1195
1207
  if (isUndefined(content)) {
1196
1208
  if (isUndefined(contentSubIdSet)) {
1197
1209
  await executeCommand(
1198
- DELETE_FROM +
1199
- escapeId(tableName) +
1200
- getWhereCondition(tableName, condition),
1210
+ DELETE_FROM + escapeId(tableName) + getWhere(tableName, condition),
1201
1211
  );
1202
1212
  }
1203
1213
  } else {
@@ -1207,8 +1217,11 @@ const getCommandFunctions = (
1207
1217
  await executeCommand(
1208
1218
  DELETE_FROM +
1209
1219
  escapeId(tableName) +
1210
- getWhereCondition(tableName, condition) +
1211
- `AND(${escapeId(rowIdColumnName)}=${getPlaceholder([1])})`,
1220
+ getWhere(
1221
+ tableName,
1222
+ condition,
1223
+ `(${escapeId(rowIdColumnName)}=${getPlaceholder([1])})`,
1224
+ ),
1212
1225
  [rowId],
1213
1226
  );
1214
1227
  } else if (!isEmpty(settingColumnNames)) {
@@ -1267,8 +1280,12 @@ const getCommandFunctions = (
1267
1280
  await executeCommand(
1268
1281
  DELETE_FROM +
1269
1282
  escapeId(tableName) +
1270
- getWhereCondition(tableName, condition) + // eslint-disable-next-line max-len
1271
- `AND${escapeId(rowIdColumnName)}NOT IN(${getPlaceholders(deleteRowIds, getPlaceholder)})`,
1283
+ getWhere(
1284
+ tableName,
1285
+ condition,
1286
+ // eslint-disable-next-line max-len
1287
+ `${escapeId(rowIdColumnName)}NOT IN(${getPlaceholders(deleteRowIds, getPlaceholder)})`,
1288
+ ),
1272
1289
  deleteRowIds,
1273
1290
  );
1274
1291
  } else if (
@@ -1276,9 +1293,7 @@ const getCommandFunctions = (
1276
1293
  collHas(schemaMap, tableName)
1277
1294
  ) {
1278
1295
  await executeCommand(
1279
- DELETE_FROM +
1280
- escapeId(tableName) +
1281
- getWhereCondition(tableName, condition),
1296
+ DELETE_FROM + escapeId(tableName) + getWhere(tableName, condition),
1282
1297
  );
1283
1298
  }
1284
1299
  }
@@ -256,8 +256,20 @@ const getPlaceholders = (array, getPlaceholder, offset = [1]) =>
256
256
  arrayMap(array, () => getPlaceholder(offset)),
257
257
  COMMA,
258
258
  );
259
- const getWhereCondition = (tableName, condition = TRUE) =>
260
- WHERE + `(${replaceTableName(condition, escapeId(tableName))})`;
259
+ const getWhere = (tableName, condition = TRUE, extraCondition) => {
260
+ const conditions = arrayFilter(
261
+ [
262
+ condition == TRUE
263
+ ? void 0
264
+ : `(${replaceTableName(condition, escapeId(tableName))})`,
265
+ extraCondition,
266
+ ],
267
+ (condition2) => !isUndefined(condition2),
268
+ );
269
+ return isEmpty(conditions)
270
+ ? EMPTY_STRING
271
+ : WHERE + arrayJoin(conditions, 'AND');
272
+ };
261
273
  const replaceTableName = (condition, tableName) =>
262
274
  strReplace(condition, TABLE_NAME_PLACEHOLDER_REGEX, tableName);
263
275
 
@@ -1038,7 +1050,7 @@ const getCommandFunctions = (
1038
1050
  await executeCommand(
1039
1051
  SELECT_STAR_FROM +
1040
1052
  escapeId(tableName) +
1041
- getWhereCondition(tableName, condition),
1053
+ getWhere(tableName, condition),
1042
1054
  ),
1043
1055
  (row) => {
1044
1056
  const rowId = row[rowIdColumnName];
@@ -1194,9 +1206,7 @@ const getCommandFunctions = (
1194
1206
  if (isUndefined(content)) {
1195
1207
  if (isUndefined(contentSubIdSet)) {
1196
1208
  await executeCommand(
1197
- DELETE_FROM +
1198
- escapeId(tableName) +
1199
- getWhereCondition(tableName, condition),
1209
+ DELETE_FROM + escapeId(tableName) + getWhere(tableName, condition),
1200
1210
  );
1201
1211
  }
1202
1212
  } else {
@@ -1206,8 +1216,11 @@ const getCommandFunctions = (
1206
1216
  await executeCommand(
1207
1217
  DELETE_FROM +
1208
1218
  escapeId(tableName) +
1209
- getWhereCondition(tableName, condition) +
1210
- `AND(${escapeId(rowIdColumnName)}=${getPlaceholder([1])})`,
1219
+ getWhere(
1220
+ tableName,
1221
+ condition,
1222
+ `(${escapeId(rowIdColumnName)}=${getPlaceholder([1])})`,
1223
+ ),
1211
1224
  [rowId],
1212
1225
  );
1213
1226
  } else if (!isEmpty(settingColumnNames)) {
@@ -1266,8 +1279,12 @@ const getCommandFunctions = (
1266
1279
  await executeCommand(
1267
1280
  DELETE_FROM +
1268
1281
  escapeId(tableName) +
1269
- getWhereCondition(tableName, condition) + // eslint-disable-next-line max-len
1270
- `AND${escapeId(rowIdColumnName)}NOT IN(${getPlaceholders(deleteRowIds, getPlaceholder)})`,
1282
+ getWhere(
1283
+ tableName,
1284
+ condition,
1285
+ // eslint-disable-next-line max-len
1286
+ `${escapeId(rowIdColumnName)}NOT IN(${getPlaceholders(deleteRowIds, getPlaceholder)})`,
1287
+ ),
1271
1288
  deleteRowIds,
1272
1289
  );
1273
1290
  } else if (
@@ -1275,9 +1292,7 @@ const getCommandFunctions = (
1275
1292
  collHas(schemaMap, tableName)
1276
1293
  ) {
1277
1294
  await executeCommand(
1278
- DELETE_FROM +
1279
- escapeId(tableName) +
1280
- getWhereCondition(tableName, condition),
1295
+ DELETE_FROM + escapeId(tableName) + getWhere(tableName, condition),
1281
1296
  );
1282
1297
  }
1283
1298
  }
@@ -256,8 +256,20 @@ const getPlaceholders = (array, getPlaceholder, offset = [1]) =>
256
256
  arrayMap(array, () => getPlaceholder(offset)),
257
257
  COMMA,
258
258
  );
259
- const getWhereCondition = (tableName, condition = TRUE) =>
260
- WHERE + `(${replaceTableName(condition, escapeId(tableName))})`;
259
+ const getWhere = (tableName, condition = TRUE, extraCondition) => {
260
+ const conditions = arrayFilter(
261
+ [
262
+ condition == TRUE
263
+ ? void 0
264
+ : `(${replaceTableName(condition, escapeId(tableName))})`,
265
+ extraCondition,
266
+ ],
267
+ (condition2) => !isUndefined(condition2),
268
+ );
269
+ return isEmpty(conditions)
270
+ ? EMPTY_STRING
271
+ : WHERE + arrayJoin(conditions, 'AND');
272
+ };
261
273
  const replaceTableName = (condition, tableName) =>
262
274
  strReplace(condition, TABLE_NAME_PLACEHOLDER_REGEX, tableName);
263
275
 
@@ -1038,7 +1050,7 @@ const getCommandFunctions = (
1038
1050
  await executeCommand(
1039
1051
  SELECT_STAR_FROM +
1040
1052
  escapeId(tableName) +
1041
- getWhereCondition(tableName, condition),
1053
+ getWhere(tableName, condition),
1042
1054
  ),
1043
1055
  (row) => {
1044
1056
  const rowId = row[rowIdColumnName];
@@ -1194,9 +1206,7 @@ const getCommandFunctions = (
1194
1206
  if (isUndefined(content)) {
1195
1207
  if (isUndefined(contentSubIdSet)) {
1196
1208
  await executeCommand(
1197
- DELETE_FROM +
1198
- escapeId(tableName) +
1199
- getWhereCondition(tableName, condition),
1209
+ DELETE_FROM + escapeId(tableName) + getWhere(tableName, condition),
1200
1210
  );
1201
1211
  }
1202
1212
  } else {
@@ -1206,8 +1216,11 @@ const getCommandFunctions = (
1206
1216
  await executeCommand(
1207
1217
  DELETE_FROM +
1208
1218
  escapeId(tableName) +
1209
- getWhereCondition(tableName, condition) +
1210
- `AND(${escapeId(rowIdColumnName)}=${getPlaceholder([1])})`,
1219
+ getWhere(
1220
+ tableName,
1221
+ condition,
1222
+ `(${escapeId(rowIdColumnName)}=${getPlaceholder([1])})`,
1223
+ ),
1211
1224
  [rowId],
1212
1225
  );
1213
1226
  } else if (!isEmpty(settingColumnNames)) {
@@ -1266,8 +1279,12 @@ const getCommandFunctions = (
1266
1279
  await executeCommand(
1267
1280
  DELETE_FROM +
1268
1281
  escapeId(tableName) +
1269
- getWhereCondition(tableName, condition) + // eslint-disable-next-line max-len
1270
- `AND${escapeId(rowIdColumnName)}NOT IN(${getPlaceholders(deleteRowIds, getPlaceholder)})`,
1282
+ getWhere(
1283
+ tableName,
1284
+ condition,
1285
+ // eslint-disable-next-line max-len
1286
+ `${escapeId(rowIdColumnName)}NOT IN(${getPlaceholders(deleteRowIds, getPlaceholder)})`,
1287
+ ),
1271
1288
  deleteRowIds,
1272
1289
  );
1273
1290
  } else if (
@@ -1275,9 +1292,7 @@ const getCommandFunctions = (
1275
1292
  collHas(schemaMap, tableName)
1276
1293
  ) {
1277
1294
  await executeCommand(
1278
- DELETE_FROM +
1279
- escapeId(tableName) +
1280
- getWhereCondition(tableName, condition),
1295
+ DELETE_FROM + escapeId(tableName) + getWhere(tableName, condition),
1281
1296
  );
1282
1297
  }
1283
1298
  }
@@ -255,8 +255,20 @@ const getPlaceholders = (array, getPlaceholder, offset = [1]) =>
255
255
  arrayMap(array, () => getPlaceholder(offset)),
256
256
  COMMA,
257
257
  );
258
- const getWhereCondition = (tableName, condition = TRUE) =>
259
- WHERE + `(${replaceTableName(condition, escapeId(tableName))})`;
258
+ const getWhere = (tableName, condition = TRUE, extraCondition) => {
259
+ const conditions = arrayFilter(
260
+ [
261
+ condition == TRUE
262
+ ? void 0
263
+ : `(${replaceTableName(condition, escapeId(tableName))})`,
264
+ extraCondition,
265
+ ],
266
+ (condition2) => !isUndefined(condition2),
267
+ );
268
+ return isEmpty(conditions)
269
+ ? EMPTY_STRING
270
+ : WHERE + arrayJoin(conditions, 'AND');
271
+ };
260
272
  const replaceTableName = (condition, tableName) =>
261
273
  strReplace(condition, TABLE_NAME_PLACEHOLDER_REGEX, tableName);
262
274
 
@@ -1037,7 +1049,7 @@ const getCommandFunctions = (
1037
1049
  await executeCommand(
1038
1050
  SELECT_STAR_FROM +
1039
1051
  escapeId(tableName) +
1040
- getWhereCondition(tableName, condition),
1052
+ getWhere(tableName, condition),
1041
1053
  ),
1042
1054
  (row) => {
1043
1055
  const rowId = row[rowIdColumnName];
@@ -1193,9 +1205,7 @@ const getCommandFunctions = (
1193
1205
  if (isUndefined(content)) {
1194
1206
  if (isUndefined(contentSubIdSet)) {
1195
1207
  await executeCommand(
1196
- DELETE_FROM +
1197
- escapeId(tableName) +
1198
- getWhereCondition(tableName, condition),
1208
+ DELETE_FROM + escapeId(tableName) + getWhere(tableName, condition),
1199
1209
  );
1200
1210
  }
1201
1211
  } else {
@@ -1205,8 +1215,11 @@ const getCommandFunctions = (
1205
1215
  await executeCommand(
1206
1216
  DELETE_FROM +
1207
1217
  escapeId(tableName) +
1208
- getWhereCondition(tableName, condition) +
1209
- `AND(${escapeId(rowIdColumnName)}=${getPlaceholder([1])})`,
1218
+ getWhere(
1219
+ tableName,
1220
+ condition,
1221
+ `(${escapeId(rowIdColumnName)}=${getPlaceholder([1])})`,
1222
+ ),
1210
1223
  [rowId],
1211
1224
  );
1212
1225
  } else if (!isEmpty(settingColumnNames)) {
@@ -1265,8 +1278,12 @@ const getCommandFunctions = (
1265
1278
  await executeCommand(
1266
1279
  DELETE_FROM +
1267
1280
  escapeId(tableName) +
1268
- getWhereCondition(tableName, condition) + // eslint-disable-next-line max-len
1269
- `AND${escapeId(rowIdColumnName)}NOT IN(${getPlaceholders(deleteRowIds, getPlaceholder)})`,
1281
+ getWhere(
1282
+ tableName,
1283
+ condition,
1284
+ // eslint-disable-next-line max-len
1285
+ `${escapeId(rowIdColumnName)}NOT IN(${getPlaceholders(deleteRowIds, getPlaceholder)})`,
1286
+ ),
1270
1287
  deleteRowIds,
1271
1288
  );
1272
1289
  } else if (
@@ -1274,9 +1291,7 @@ const getCommandFunctions = (
1274
1291
  collHas(schemaMap, tableName)
1275
1292
  ) {
1276
1293
  await executeCommand(
1277
- DELETE_FROM +
1278
- escapeId(tableName) +
1279
- getWhereCondition(tableName, condition),
1294
+ DELETE_FROM + escapeId(tableName) + getWhere(tableName, condition),
1280
1295
  );
1281
1296
  }
1282
1297
  }
@@ -255,8 +255,20 @@ const getPlaceholders = (array, getPlaceholder, offset = [1]) =>
255
255
  arrayMap(array, () => getPlaceholder(offset)),
256
256
  COMMA,
257
257
  );
258
- const getWhereCondition = (tableName, condition = TRUE) =>
259
- WHERE + `(${replaceTableName(condition, escapeId(tableName))})`;
258
+ const getWhere = (tableName, condition = TRUE, extraCondition) => {
259
+ const conditions = arrayFilter(
260
+ [
261
+ condition == TRUE
262
+ ? void 0
263
+ : `(${replaceTableName(condition, escapeId(tableName))})`,
264
+ extraCondition,
265
+ ],
266
+ (condition2) => !isUndefined(condition2),
267
+ );
268
+ return isEmpty(conditions)
269
+ ? EMPTY_STRING
270
+ : WHERE + arrayJoin(conditions, 'AND');
271
+ };
260
272
  const replaceTableName = (condition, tableName) =>
261
273
  strReplace(condition, TABLE_NAME_PLACEHOLDER_REGEX, tableName);
262
274
 
@@ -1037,7 +1049,7 @@ const getCommandFunctions = (
1037
1049
  await executeCommand(
1038
1050
  SELECT_STAR_FROM +
1039
1051
  escapeId(tableName) +
1040
- getWhereCondition(tableName, condition),
1052
+ getWhere(tableName, condition),
1041
1053
  ),
1042
1054
  (row) => {
1043
1055
  const rowId = row[rowIdColumnName];
@@ -1193,9 +1205,7 @@ const getCommandFunctions = (
1193
1205
  if (isUndefined(content)) {
1194
1206
  if (isUndefined(contentSubIdSet)) {
1195
1207
  await executeCommand(
1196
- DELETE_FROM +
1197
- escapeId(tableName) +
1198
- getWhereCondition(tableName, condition),
1208
+ DELETE_FROM + escapeId(tableName) + getWhere(tableName, condition),
1199
1209
  );
1200
1210
  }
1201
1211
  } else {
@@ -1205,8 +1215,11 @@ const getCommandFunctions = (
1205
1215
  await executeCommand(
1206
1216
  DELETE_FROM +
1207
1217
  escapeId(tableName) +
1208
- getWhereCondition(tableName, condition) +
1209
- `AND(${escapeId(rowIdColumnName)}=${getPlaceholder([1])})`,
1218
+ getWhere(
1219
+ tableName,
1220
+ condition,
1221
+ `(${escapeId(rowIdColumnName)}=${getPlaceholder([1])})`,
1222
+ ),
1210
1223
  [rowId],
1211
1224
  );
1212
1225
  } else if (!isEmpty(settingColumnNames)) {
@@ -1265,8 +1278,12 @@ const getCommandFunctions = (
1265
1278
  await executeCommand(
1266
1279
  DELETE_FROM +
1267
1280
  escapeId(tableName) +
1268
- getWhereCondition(tableName, condition) + // eslint-disable-next-line max-len
1269
- `AND${escapeId(rowIdColumnName)}NOT IN(${getPlaceholders(deleteRowIds, getPlaceholder)})`,
1281
+ getWhere(
1282
+ tableName,
1283
+ condition,
1284
+ // eslint-disable-next-line max-len
1285
+ `${escapeId(rowIdColumnName)}NOT IN(${getPlaceholders(deleteRowIds, getPlaceholder)})`,
1286
+ ),
1270
1287
  deleteRowIds,
1271
1288
  );
1272
1289
  } else if (
@@ -1274,9 +1291,7 @@ const getCommandFunctions = (
1274
1291
  collHas(schemaMap, tableName)
1275
1292
  ) {
1276
1293
  await executeCommand(
1277
- DELETE_FROM +
1278
- escapeId(tableName) +
1279
- getWhereCondition(tableName, condition),
1294
+ DELETE_FROM + escapeId(tableName) + getWhere(tableName, condition),
1280
1295
  );
1281
1296
  }
1282
1297
  }