tinybase 10.0.0-beta.1 → 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 (149) 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 +1 -0
  4. package/@types/indexes/with-schemas/index.d.ts +1 -0
  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/min/omni/index.js +1 -1
  34. package/min/omni/index.js.gz +0 -0
  35. package/min/omni/with-schemas/index.js +1 -1
  36. package/min/omni/with-schemas/index.js.gz +0 -0
  37. package/min/persisters/index.js +1 -1
  38. package/min/persisters/index.js.gz +0 -0
  39. package/min/persisters/persister-better-sqlite3/index.js +1 -1
  40. package/min/persisters/persister-better-sqlite3/index.js.gz +0 -0
  41. package/min/persisters/persister-better-sqlite3/with-schemas/index.js +1 -1
  42. package/min/persisters/persister-better-sqlite3/with-schemas/index.js.gz +0 -0
  43. package/min/persisters/persister-capacitor-sqlite/index.js +1 -1
  44. package/min/persisters/persister-capacitor-sqlite/index.js.gz +0 -0
  45. package/min/persisters/persister-capacitor-sqlite/with-schemas/index.js +1 -1
  46. package/min/persisters/persister-capacitor-sqlite/with-schemas/index.js.gz +0 -0
  47. package/min/persisters/persister-cr-sqlite-wasm/index.js +1 -1
  48. package/min/persisters/persister-cr-sqlite-wasm/index.js.gz +0 -0
  49. package/min/persisters/persister-cr-sqlite-wasm/with-schemas/index.js +1 -1
  50. package/min/persisters/persister-cr-sqlite-wasm/with-schemas/index.js.gz +0 -0
  51. package/min/persisters/persister-durable-object-sql-storage/index.js +1 -1
  52. package/min/persisters/persister-durable-object-sql-storage/index.js.gz +0 -0
  53. package/min/persisters/persister-durable-object-sql-storage/with-schemas/index.js +1 -1
  54. package/min/persisters/persister-durable-object-sql-storage/with-schemas/index.js.gz +0 -0
  55. package/min/persisters/persister-electric-sql/index.js +1 -1
  56. package/min/persisters/persister-electric-sql/index.js.gz +0 -0
  57. package/min/persisters/persister-electric-sql/with-schemas/index.js +1 -1
  58. package/min/persisters/persister-electric-sql/with-schemas/index.js.gz +0 -0
  59. package/min/persisters/persister-expo-sqlite/index.js +1 -1
  60. package/min/persisters/persister-expo-sqlite/index.js.gz +0 -0
  61. package/min/persisters/persister-expo-sqlite/with-schemas/index.js +1 -1
  62. package/min/persisters/persister-expo-sqlite/with-schemas/index.js.gz +0 -0
  63. package/min/persisters/persister-libsql/index.js +1 -1
  64. package/min/persisters/persister-libsql/index.js.gz +0 -0
  65. package/min/persisters/persister-libsql/with-schemas/index.js +1 -1
  66. package/min/persisters/persister-libsql/with-schemas/index.js.gz +0 -0
  67. package/min/persisters/persister-pg/index.js +1 -1
  68. package/min/persisters/persister-pg/index.js.gz +0 -0
  69. package/min/persisters/persister-pg/with-schemas/index.js +1 -1
  70. package/min/persisters/persister-pg/with-schemas/index.js.gz +0 -0
  71. package/min/persisters/persister-pglite/index.js +1 -1
  72. package/min/persisters/persister-pglite/index.js.gz +0 -0
  73. package/min/persisters/persister-pglite/with-schemas/index.js +1 -1
  74. package/min/persisters/persister-pglite/with-schemas/index.js.gz +0 -0
  75. package/min/persisters/persister-postgres/index.js +1 -1
  76. package/min/persisters/persister-postgres/index.js.gz +0 -0
  77. package/min/persisters/persister-postgres/with-schemas/index.js +1 -1
  78. package/min/persisters/persister-postgres/with-schemas/index.js.gz +0 -0
  79. package/min/persisters/persister-powersync/index.js +1 -1
  80. package/min/persisters/persister-powersync/index.js.gz +0 -0
  81. package/min/persisters/persister-powersync/with-schemas/index.js +1 -1
  82. package/min/persisters/persister-powersync/with-schemas/index.js.gz +0 -0
  83. package/min/persisters/persister-react-native-sqlite/index.js +1 -1
  84. package/min/persisters/persister-react-native-sqlite/index.js.gz +0 -0
  85. package/min/persisters/persister-react-native-sqlite/with-schemas/index.js +1 -1
  86. package/min/persisters/persister-react-native-sqlite/with-schemas/index.js.gz +0 -0
  87. package/min/persisters/persister-sqlite-bun/index.js +1 -1
  88. package/min/persisters/persister-sqlite-bun/index.js.gz +0 -0
  89. package/min/persisters/persister-sqlite-bun/with-schemas/index.js +1 -1
  90. package/min/persisters/persister-sqlite-bun/with-schemas/index.js.gz +0 -0
  91. package/min/persisters/persister-sqlite-node/index.js +1 -1
  92. package/min/persisters/persister-sqlite-node/index.js.gz +0 -0
  93. package/min/persisters/persister-sqlite-node/with-schemas/index.js +1 -1
  94. package/min/persisters/persister-sqlite-node/with-schemas/index.js.gz +0 -0
  95. package/min/persisters/persister-sqlite-wasm/index.js +1 -1
  96. package/min/persisters/persister-sqlite-wasm/index.js.gz +0 -0
  97. package/min/persisters/persister-sqlite-wasm/with-schemas/index.js +1 -1
  98. package/min/persisters/persister-sqlite-wasm/with-schemas/index.js.gz +0 -0
  99. package/min/persisters/persister-sqlite3/index.js +1 -1
  100. package/min/persisters/persister-sqlite3/index.js.gz +0 -0
  101. package/min/persisters/persister-sqlite3/with-schemas/index.js +1 -1
  102. package/min/persisters/persister-sqlite3/with-schemas/index.js.gz +0 -0
  103. package/min/persisters/persister-tinyjoin/index.js +1 -0
  104. package/min/persisters/persister-tinyjoin/index.js.gz +0 -0
  105. package/min/persisters/persister-tinyjoin/with-schemas/index.js +1 -0
  106. package/min/persisters/persister-tinyjoin/with-schemas/index.js.gz +0 -0
  107. package/min/persisters/with-schemas/index.js +1 -1
  108. package/min/persisters/with-schemas/index.js.gz +0 -0
  109. package/omni/index.js +146 -66
  110. package/omni/with-schemas/index.js +146 -66
  111. package/package.json +41 -1
  112. package/persisters/index.js +28 -13
  113. package/persisters/persister-better-sqlite3/index.js +70 -55
  114. package/persisters/persister-better-sqlite3/with-schemas/index.js +70 -55
  115. package/persisters/persister-capacitor-sqlite/index.js +70 -55
  116. package/persisters/persister-capacitor-sqlite/with-schemas/index.js +70 -55
  117. package/persisters/persister-cr-sqlite-wasm/index.js +70 -55
  118. package/persisters/persister-cr-sqlite-wasm/with-schemas/index.js +70 -55
  119. package/persisters/persister-durable-object-sql-storage/index.js +28 -13
  120. package/persisters/persister-durable-object-sql-storage/with-schemas/index.js +28 -13
  121. package/persisters/persister-electric-sql/index.js +70 -55
  122. package/persisters/persister-electric-sql/with-schemas/index.js +70 -55
  123. package/persisters/persister-expo-sqlite/index.js +70 -55
  124. package/persisters/persister-expo-sqlite/with-schemas/index.js +70 -55
  125. package/persisters/persister-libsql/index.js +70 -55
  126. package/persisters/persister-libsql/with-schemas/index.js +70 -55
  127. package/persisters/persister-pg/index.js +77 -62
  128. package/persisters/persister-pg/with-schemas/index.js +77 -62
  129. package/persisters/persister-pglite/index.js +28 -13
  130. package/persisters/persister-pglite/with-schemas/index.js +28 -13
  131. package/persisters/persister-postgres/index.js +28 -13
  132. package/persisters/persister-postgres/with-schemas/index.js +28 -13
  133. package/persisters/persister-powersync/index.js +81 -66
  134. package/persisters/persister-powersync/with-schemas/index.js +81 -66
  135. package/persisters/persister-react-native-sqlite/index.js +70 -55
  136. package/persisters/persister-react-native-sqlite/with-schemas/index.js +70 -55
  137. package/persisters/persister-sqlite-bun/index.js +70 -55
  138. package/persisters/persister-sqlite-bun/with-schemas/index.js +70 -55
  139. package/persisters/persister-sqlite-node/index.js +70 -55
  140. package/persisters/persister-sqlite-node/with-schemas/index.js +70 -55
  141. package/persisters/persister-sqlite-wasm/index.js +70 -55
  142. package/persisters/persister-sqlite-wasm/with-schemas/index.js +70 -55
  143. package/persisters/persister-sqlite3/index.js +70 -55
  144. package/persisters/persister-sqlite3/with-schemas/index.js +70 -55
  145. package/persisters/persister-tinyjoin/index.js +1710 -0
  146. package/persisters/persister-tinyjoin/with-schemas/index.js +1710 -0
  147. package/persisters/with-schemas/index.js +28 -13
  148. package/readme.md +3 -3
  149. package/releases.md +20 -1
@@ -105,50 +105,6 @@ const arrayClear = (array, to = size(array)) => array.splice(0, to);
105
105
  const arrayPush = (array, ...values) => array.push(...values);
106
106
  const arrayShift = (array) => array.shift();
107
107
 
108
- const SINGLE_ROW_ID = '_';
109
- const DEFAULT_ROW_ID_COLUMN_NAME = '_id';
110
- const SELECT = 'SELECT';
111
- const WHERE = 'WHERE';
112
- const TABLE = 'TABLE';
113
- const INSERT = 'INSERT';
114
- const DELETE = 'DELETE';
115
- const UPDATE = 'UPDATE';
116
- const ALTER_TABLE = 'ALTER ' + TABLE;
117
- const FROM = 'FROM';
118
- const DELETE_FROM = DELETE + ' ' + FROM;
119
- const SELECT_STAR_FROM = SELECT + '*' + FROM;
120
- const PRAGMA = 'pragma_';
121
- const DATA_VERSION = 'data_version';
122
- const SCHEMA_VERSION = 'schema_version';
123
- const PRAGMA_TABLE = 'pragma_table_';
124
- const CREATE = 'CREATE ';
125
- const CREATE_TABLE = CREATE + TABLE;
126
- const TABLE_NAME_PLACEHOLDER_REGEX = /\$tableName/g;
127
- const getWrappedCommand = (executeCommand, onSqlCommand) =>
128
- onSqlCommand
129
- ? async (sql, params) => {
130
- onSqlCommand(sql, params);
131
- return await executeCommand(sql, params);
132
- }
133
- : executeCommand;
134
- const escapeId = (str) =>
135
- arrayJoin(
136
- arrayMap(strSplit(str, DOT), (part) => `"${strReplace(part, /"/g, '""')}"`),
137
- DOT,
138
- );
139
- const escapeColumnNames = (...columnNames) =>
140
- arrayJoin(arrayMap(columnNames, escapeId), COMMA);
141
- const anonymousPlaceholder = () => '?';
142
- const getPlaceholders = (array, getPlaceholder, offset = [1]) =>
143
- arrayJoin(
144
- arrayMap(array, () => getPlaceholder(offset)),
145
- COMMA,
146
- );
147
- const getWhereCondition = (tableName, condition = TRUE) =>
148
- WHERE + `(${replaceTableName(condition, escapeId(tableName))})`;
149
- const replaceTableName = (condition, tableName) =>
150
- strReplace(condition, TABLE_NAME_PLACEHOLDER_REGEX, tableName);
151
-
152
108
  const object = Object;
153
109
  const getPrototypeOf = (obj) => object.getPrototypeOf(obj);
154
110
  const objEntries = object.entries;
@@ -198,6 +154,62 @@ const objValues = (obj) => object.values(obj);
198
154
  const objSize = (obj) => size(objIds(obj));
199
155
  const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
200
156
 
157
+ const SINGLE_ROW_ID = '_';
158
+ const DEFAULT_ROW_ID_COLUMN_NAME = '_id';
159
+ const SELECT = 'SELECT';
160
+ const WHERE = 'WHERE';
161
+ const TABLE = 'TABLE';
162
+ const INSERT = 'INSERT';
163
+ const DELETE = 'DELETE';
164
+ const UPDATE = 'UPDATE';
165
+ const ALTER_TABLE = 'ALTER ' + TABLE;
166
+ const FROM = 'FROM';
167
+ const DELETE_FROM = DELETE + ' ' + FROM;
168
+ const SELECT_STAR_FROM = SELECT + '*' + FROM;
169
+ const PRAGMA = 'pragma_';
170
+ const DATA_VERSION = 'data_version';
171
+ const SCHEMA_VERSION = 'schema_version';
172
+ const PRAGMA_TABLE = 'pragma_table_';
173
+ const CREATE = 'CREATE ';
174
+ const CREATE_TABLE = CREATE + TABLE;
175
+ const TABLE_NAME_PLACEHOLDER_REGEX = /\$tableName/g;
176
+ const getWrappedCommand = (executeCommand, onSqlCommand) =>
177
+ onSqlCommand
178
+ ? async (sql, params) => {
179
+ onSqlCommand(sql, params);
180
+ return await executeCommand(sql, params);
181
+ }
182
+ : executeCommand;
183
+ const escapeId = (str) =>
184
+ arrayJoin(
185
+ arrayMap(strSplit(str, DOT), (part) => `"${strReplace(part, /"/g, '""')}"`),
186
+ DOT,
187
+ );
188
+ const escapeColumnNames = (...columnNames) =>
189
+ arrayJoin(arrayMap(columnNames, escapeId), COMMA);
190
+ const anonymousPlaceholder = () => '?';
191
+ const getPlaceholders = (array, getPlaceholder, offset = [1]) =>
192
+ arrayJoin(
193
+ arrayMap(array, () => getPlaceholder(offset)),
194
+ COMMA,
195
+ );
196
+ const getWhere = (tableName, condition = TRUE, extraCondition) => {
197
+ const conditions = arrayFilter(
198
+ [
199
+ condition == TRUE
200
+ ? void 0
201
+ : `(${replaceTableName(condition, escapeId(tableName))})`,
202
+ extraCondition,
203
+ ],
204
+ (condition2) => !isUndefined(condition2),
205
+ );
206
+ return isEmpty(conditions)
207
+ ? EMPTY_STRING
208
+ : WHERE + arrayJoin(conditions, 'AND');
209
+ };
210
+ const replaceTableName = (condition, tableName) =>
211
+ strReplace(condition, TABLE_NAME_PLACEHOLDER_REGEX, tableName);
212
+
201
213
  const map = Map;
202
214
  const mapNew = (entries) => new map(entries);
203
215
  const mapGet = (map2, key) => map2?.get(key);
@@ -1045,7 +1057,7 @@ const getCommandFunctions = (
1045
1057
  await executeCommand(
1046
1058
  SELECT_STAR_FROM +
1047
1059
  escapeId(tableName) +
1048
- getWhereCondition(tableName, condition),
1060
+ getWhere(tableName, condition),
1049
1061
  ),
1050
1062
  (row) => {
1051
1063
  const rowId = row[rowIdColumnName];
@@ -1201,9 +1213,7 @@ const getCommandFunctions = (
1201
1213
  if (isUndefined(content)) {
1202
1214
  if (isUndefined(contentSubIdSet)) {
1203
1215
  await executeCommand(
1204
- DELETE_FROM +
1205
- escapeId(tableName) +
1206
- getWhereCondition(tableName, condition),
1216
+ DELETE_FROM + escapeId(tableName) + getWhere(tableName, condition),
1207
1217
  );
1208
1218
  }
1209
1219
  } else {
@@ -1213,8 +1223,11 @@ const getCommandFunctions = (
1213
1223
  await executeCommand(
1214
1224
  DELETE_FROM +
1215
1225
  escapeId(tableName) +
1216
- getWhereCondition(tableName, condition) +
1217
- `AND(${escapeId(rowIdColumnName)}=${getPlaceholder([1])})`,
1226
+ getWhere(
1227
+ tableName,
1228
+ condition,
1229
+ `(${escapeId(rowIdColumnName)}=${getPlaceholder([1])})`,
1230
+ ),
1218
1231
  [rowId],
1219
1232
  );
1220
1233
  } else if (!isEmpty(settingColumnNames)) {
@@ -1273,8 +1286,12 @@ const getCommandFunctions = (
1273
1286
  await executeCommand(
1274
1287
  DELETE_FROM +
1275
1288
  escapeId(tableName) +
1276
- getWhereCondition(tableName, condition) + // eslint-disable-next-line max-len
1277
- `AND${escapeId(rowIdColumnName)}NOT IN(${getPlaceholders(deleteRowIds, getPlaceholder)})`,
1289
+ getWhere(
1290
+ tableName,
1291
+ condition,
1292
+ // eslint-disable-next-line max-len
1293
+ `${escapeId(rowIdColumnName)}NOT IN(${getPlaceholders(deleteRowIds, getPlaceholder)})`,
1294
+ ),
1278
1295
  deleteRowIds,
1279
1296
  );
1280
1297
  } else if (
@@ -1282,9 +1299,7 @@ const getCommandFunctions = (
1282
1299
  collHas(schemaMap, tableName)
1283
1300
  ) {
1284
1301
  await executeCommand(
1285
- DELETE_FROM +
1286
- escapeId(tableName) +
1287
- getWhereCondition(tableName, condition),
1302
+ DELETE_FROM + escapeId(tableName) + getWhere(tableName, condition),
1288
1303
  );
1289
1304
  }
1290
1305
  }
@@ -105,50 +105,6 @@ const tryFinallyAsync = async (action, finallyAction) => {
105
105
  }
106
106
  };
107
107
 
108
- const SINGLE_ROW_ID = '_';
109
- const DEFAULT_ROW_ID_COLUMN_NAME = '_id';
110
- const SELECT = 'SELECT';
111
- const WHERE = 'WHERE';
112
- const TABLE = 'TABLE';
113
- const INSERT = 'INSERT';
114
- const DELETE = 'DELETE';
115
- const UPDATE = 'UPDATE';
116
- const ALTER_TABLE = 'ALTER ' + TABLE;
117
- const FROM = 'FROM';
118
- const DELETE_FROM = DELETE + ' ' + FROM;
119
- const SELECT_STAR_FROM = SELECT + '*' + FROM;
120
- const PRAGMA = 'pragma_';
121
- const DATA_VERSION = 'data_version';
122
- const SCHEMA_VERSION = 'schema_version';
123
- const PRAGMA_TABLE = 'pragma_table_';
124
- const CREATE = 'CREATE ';
125
- const CREATE_TABLE = CREATE + TABLE;
126
- const TABLE_NAME_PLACEHOLDER_REGEX = /\$tableName/g;
127
- const getWrappedCommand = (executeCommand, onSqlCommand) =>
128
- onSqlCommand
129
- ? async (sql, params) => {
130
- onSqlCommand(sql, params);
131
- return await executeCommand(sql, params);
132
- }
133
- : executeCommand;
134
- const escapeId = (str) =>
135
- arrayJoin(
136
- arrayMap(strSplit(str, DOT), (part) => `"${strReplace(part, /"/g, '""')}"`),
137
- DOT,
138
- );
139
- const escapeColumnNames = (...columnNames) =>
140
- arrayJoin(arrayMap(columnNames, escapeId), COMMA);
141
- const anonymousPlaceholder = () => '?';
142
- const getPlaceholders = (array, getPlaceholder, offset = [1]) =>
143
- arrayJoin(
144
- arrayMap(array, () => getPlaceholder(offset)),
145
- COMMA,
146
- );
147
- const getWhereCondition = (tableName, condition = TRUE) =>
148
- WHERE + `(${replaceTableName(condition, escapeId(tableName))})`;
149
- const replaceTableName = (condition, tableName) =>
150
- strReplace(condition, TABLE_NAME_PLACEHOLDER_REGEX, tableName);
151
-
152
108
  const object = Object;
153
109
  const getPrototypeOf = (obj) => object.getPrototypeOf(obj);
154
110
  const objEntries = object.entries;
@@ -198,6 +154,62 @@ const objValues = (obj) => object.values(obj);
198
154
  const objSize = (obj) => size(objIds(obj));
199
155
  const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
200
156
 
157
+ const SINGLE_ROW_ID = '_';
158
+ const DEFAULT_ROW_ID_COLUMN_NAME = '_id';
159
+ const SELECT = 'SELECT';
160
+ const WHERE = 'WHERE';
161
+ const TABLE = 'TABLE';
162
+ const INSERT = 'INSERT';
163
+ const DELETE = 'DELETE';
164
+ const UPDATE = 'UPDATE';
165
+ const ALTER_TABLE = 'ALTER ' + TABLE;
166
+ const FROM = 'FROM';
167
+ const DELETE_FROM = DELETE + ' ' + FROM;
168
+ const SELECT_STAR_FROM = SELECT + '*' + FROM;
169
+ const PRAGMA = 'pragma_';
170
+ const DATA_VERSION = 'data_version';
171
+ const SCHEMA_VERSION = 'schema_version';
172
+ const PRAGMA_TABLE = 'pragma_table_';
173
+ const CREATE = 'CREATE ';
174
+ const CREATE_TABLE = CREATE + TABLE;
175
+ const TABLE_NAME_PLACEHOLDER_REGEX = /\$tableName/g;
176
+ const getWrappedCommand = (executeCommand, onSqlCommand) =>
177
+ onSqlCommand
178
+ ? async (sql, params) => {
179
+ onSqlCommand(sql, params);
180
+ return await executeCommand(sql, params);
181
+ }
182
+ : executeCommand;
183
+ const escapeId = (str) =>
184
+ arrayJoin(
185
+ arrayMap(strSplit(str, DOT), (part) => `"${strReplace(part, /"/g, '""')}"`),
186
+ DOT,
187
+ );
188
+ const escapeColumnNames = (...columnNames) =>
189
+ arrayJoin(arrayMap(columnNames, escapeId), COMMA);
190
+ const anonymousPlaceholder = () => '?';
191
+ const getPlaceholders = (array, getPlaceholder, offset = [1]) =>
192
+ arrayJoin(
193
+ arrayMap(array, () => getPlaceholder(offset)),
194
+ COMMA,
195
+ );
196
+ const getWhere = (tableName, condition = TRUE, extraCondition) => {
197
+ const conditions = arrayFilter(
198
+ [
199
+ condition == TRUE
200
+ ? void 0
201
+ : `(${replaceTableName(condition, escapeId(tableName))})`,
202
+ extraCondition,
203
+ ],
204
+ (condition2) => !isUndefined(condition2),
205
+ );
206
+ return isEmpty(conditions)
207
+ ? EMPTY_STRING
208
+ : WHERE + arrayJoin(conditions, 'AND');
209
+ };
210
+ const replaceTableName = (condition, tableName) =>
211
+ strReplace(condition, TABLE_NAME_PLACEHOLDER_REGEX, tableName);
212
+
201
213
  const map = Map;
202
214
  const mapNew = (entries) => new map(entries);
203
215
  const mapGet = (map2, key) => map2?.get(key);
@@ -1045,7 +1057,7 @@ const getCommandFunctions = (
1045
1057
  await executeCommand(
1046
1058
  SELECT_STAR_FROM +
1047
1059
  escapeId(tableName) +
1048
- getWhereCondition(tableName, condition),
1060
+ getWhere(tableName, condition),
1049
1061
  ),
1050
1062
  (row) => {
1051
1063
  const rowId = row[rowIdColumnName];
@@ -1201,9 +1213,7 @@ const getCommandFunctions = (
1201
1213
  if (isUndefined(content)) {
1202
1214
  if (isUndefined(contentSubIdSet)) {
1203
1215
  await executeCommand(
1204
- DELETE_FROM +
1205
- escapeId(tableName) +
1206
- getWhereCondition(tableName, condition),
1216
+ DELETE_FROM + escapeId(tableName) + getWhere(tableName, condition),
1207
1217
  );
1208
1218
  }
1209
1219
  } else {
@@ -1213,8 +1223,11 @@ const getCommandFunctions = (
1213
1223
  await executeCommand(
1214
1224
  DELETE_FROM +
1215
1225
  escapeId(tableName) +
1216
- getWhereCondition(tableName, condition) +
1217
- `AND(${escapeId(rowIdColumnName)}=${getPlaceholder([1])})`,
1226
+ getWhere(
1227
+ tableName,
1228
+ condition,
1229
+ `(${escapeId(rowIdColumnName)}=${getPlaceholder([1])})`,
1230
+ ),
1218
1231
  [rowId],
1219
1232
  );
1220
1233
  } else if (!isEmpty(settingColumnNames)) {
@@ -1273,8 +1286,12 @@ const getCommandFunctions = (
1273
1286
  await executeCommand(
1274
1287
  DELETE_FROM +
1275
1288
  escapeId(tableName) +
1276
- getWhereCondition(tableName, condition) + // eslint-disable-next-line max-len
1277
- `AND${escapeId(rowIdColumnName)}NOT IN(${getPlaceholders(deleteRowIds, getPlaceholder)})`,
1289
+ getWhere(
1290
+ tableName,
1291
+ condition,
1292
+ // eslint-disable-next-line max-len
1293
+ `${escapeId(rowIdColumnName)}NOT IN(${getPlaceholders(deleteRowIds, getPlaceholder)})`,
1294
+ ),
1278
1295
  deleteRowIds,
1279
1296
  );
1280
1297
  } else if (
@@ -1282,9 +1299,7 @@ const getCommandFunctions = (
1282
1299
  collHas(schemaMap, tableName)
1283
1300
  ) {
1284
1301
  await executeCommand(
1285
- DELETE_FROM +
1286
- escapeId(tableName) +
1287
- getWhereCondition(tableName, condition),
1302
+ DELETE_FROM + escapeId(tableName) + getWhere(tableName, condition),
1288
1303
  );
1289
1304
  }
1290
1305
  }
@@ -105,50 +105,6 @@ const tryFinallyAsync = async (action, finallyAction) => {
105
105
  }
106
106
  };
107
107
 
108
- const SINGLE_ROW_ID = '_';
109
- const DEFAULT_ROW_ID_COLUMN_NAME = '_id';
110
- const SELECT = 'SELECT';
111
- const WHERE = 'WHERE';
112
- const TABLE = 'TABLE';
113
- const INSERT = 'INSERT';
114
- const DELETE = 'DELETE';
115
- const UPDATE = 'UPDATE';
116
- const ALTER_TABLE = 'ALTER ' + TABLE;
117
- const FROM = 'FROM';
118
- const DELETE_FROM = DELETE + ' ' + FROM;
119
- const SELECT_STAR_FROM = SELECT + '*' + FROM;
120
- const PRAGMA = 'pragma_';
121
- const DATA_VERSION = 'data_version';
122
- const SCHEMA_VERSION = 'schema_version';
123
- const PRAGMA_TABLE = 'pragma_table_';
124
- const CREATE = 'CREATE ';
125
- const CREATE_TABLE = CREATE + TABLE;
126
- const TABLE_NAME_PLACEHOLDER_REGEX = /\$tableName/g;
127
- const getWrappedCommand = (executeCommand, onSqlCommand) =>
128
- onSqlCommand
129
- ? async (sql, params) => {
130
- onSqlCommand(sql, params);
131
- return await executeCommand(sql, params);
132
- }
133
- : executeCommand;
134
- const escapeId = (str) =>
135
- arrayJoin(
136
- arrayMap(strSplit(str, DOT), (part) => `"${strReplace(part, /"/g, '""')}"`),
137
- DOT,
138
- );
139
- const escapeColumnNames = (...columnNames) =>
140
- arrayJoin(arrayMap(columnNames, escapeId), COMMA);
141
- const anonymousPlaceholder = () => '?';
142
- const getPlaceholders = (array, getPlaceholder, offset = [1]) =>
143
- arrayJoin(
144
- arrayMap(array, () => getPlaceholder(offset)),
145
- COMMA,
146
- );
147
- const getWhereCondition = (tableName, condition = TRUE) =>
148
- WHERE + `(${replaceTableName(condition, escapeId(tableName))})`;
149
- const replaceTableName = (condition, tableName) =>
150
- strReplace(condition, TABLE_NAME_PLACEHOLDER_REGEX, tableName);
151
-
152
108
  const object = Object;
153
109
  const getPrototypeOf = (obj) => object.getPrototypeOf(obj);
154
110
  const objEntries = object.entries;
@@ -198,6 +154,62 @@ const objValues = (obj) => object.values(obj);
198
154
  const objSize = (obj) => size(objIds(obj));
199
155
  const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
200
156
 
157
+ const SINGLE_ROW_ID = '_';
158
+ const DEFAULT_ROW_ID_COLUMN_NAME = '_id';
159
+ const SELECT = 'SELECT';
160
+ const WHERE = 'WHERE';
161
+ const TABLE = 'TABLE';
162
+ const INSERT = 'INSERT';
163
+ const DELETE = 'DELETE';
164
+ const UPDATE = 'UPDATE';
165
+ const ALTER_TABLE = 'ALTER ' + TABLE;
166
+ const FROM = 'FROM';
167
+ const DELETE_FROM = DELETE + ' ' + FROM;
168
+ const SELECT_STAR_FROM = SELECT + '*' + FROM;
169
+ const PRAGMA = 'pragma_';
170
+ const DATA_VERSION = 'data_version';
171
+ const SCHEMA_VERSION = 'schema_version';
172
+ const PRAGMA_TABLE = 'pragma_table_';
173
+ const CREATE = 'CREATE ';
174
+ const CREATE_TABLE = CREATE + TABLE;
175
+ const TABLE_NAME_PLACEHOLDER_REGEX = /\$tableName/g;
176
+ const getWrappedCommand = (executeCommand, onSqlCommand) =>
177
+ onSqlCommand
178
+ ? async (sql, params) => {
179
+ onSqlCommand(sql, params);
180
+ return await executeCommand(sql, params);
181
+ }
182
+ : executeCommand;
183
+ const escapeId = (str) =>
184
+ arrayJoin(
185
+ arrayMap(strSplit(str, DOT), (part) => `"${strReplace(part, /"/g, '""')}"`),
186
+ DOT,
187
+ );
188
+ const escapeColumnNames = (...columnNames) =>
189
+ arrayJoin(arrayMap(columnNames, escapeId), COMMA);
190
+ const anonymousPlaceholder = () => '?';
191
+ const getPlaceholders = (array, getPlaceholder, offset = [1]) =>
192
+ arrayJoin(
193
+ arrayMap(array, () => getPlaceholder(offset)),
194
+ COMMA,
195
+ );
196
+ const getWhere = (tableName, condition = TRUE, extraCondition) => {
197
+ const conditions = arrayFilter(
198
+ [
199
+ condition == TRUE
200
+ ? void 0
201
+ : `(${replaceTableName(condition, escapeId(tableName))})`,
202
+ extraCondition,
203
+ ],
204
+ (condition2) => !isUndefined(condition2),
205
+ );
206
+ return isEmpty(conditions)
207
+ ? EMPTY_STRING
208
+ : WHERE + arrayJoin(conditions, 'AND');
209
+ };
210
+ const replaceTableName = (condition, tableName) =>
211
+ strReplace(condition, TABLE_NAME_PLACEHOLDER_REGEX, tableName);
212
+
201
213
  const map = Map;
202
214
  const mapNew = (entries) => new map(entries);
203
215
  const mapGet = (map2, key) => map2?.get(key);
@@ -1045,7 +1057,7 @@ const getCommandFunctions = (
1045
1057
  await executeCommand(
1046
1058
  SELECT_STAR_FROM +
1047
1059
  escapeId(tableName) +
1048
- getWhereCondition(tableName, condition),
1060
+ getWhere(tableName, condition),
1049
1061
  ),
1050
1062
  (row) => {
1051
1063
  const rowId = row[rowIdColumnName];
@@ -1201,9 +1213,7 @@ const getCommandFunctions = (
1201
1213
  if (isUndefined(content)) {
1202
1214
  if (isUndefined(contentSubIdSet)) {
1203
1215
  await executeCommand(
1204
- DELETE_FROM +
1205
- escapeId(tableName) +
1206
- getWhereCondition(tableName, condition),
1216
+ DELETE_FROM + escapeId(tableName) + getWhere(tableName, condition),
1207
1217
  );
1208
1218
  }
1209
1219
  } else {
@@ -1213,8 +1223,11 @@ const getCommandFunctions = (
1213
1223
  await executeCommand(
1214
1224
  DELETE_FROM +
1215
1225
  escapeId(tableName) +
1216
- getWhereCondition(tableName, condition) +
1217
- `AND(${escapeId(rowIdColumnName)}=${getPlaceholder([1])})`,
1226
+ getWhere(
1227
+ tableName,
1228
+ condition,
1229
+ `(${escapeId(rowIdColumnName)}=${getPlaceholder([1])})`,
1230
+ ),
1218
1231
  [rowId],
1219
1232
  );
1220
1233
  } else if (!isEmpty(settingColumnNames)) {
@@ -1273,8 +1286,12 @@ const getCommandFunctions = (
1273
1286
  await executeCommand(
1274
1287
  DELETE_FROM +
1275
1288
  escapeId(tableName) +
1276
- getWhereCondition(tableName, condition) + // eslint-disable-next-line max-len
1277
- `AND${escapeId(rowIdColumnName)}NOT IN(${getPlaceholders(deleteRowIds, getPlaceholder)})`,
1289
+ getWhere(
1290
+ tableName,
1291
+ condition,
1292
+ // eslint-disable-next-line max-len
1293
+ `${escapeId(rowIdColumnName)}NOT IN(${getPlaceholders(deleteRowIds, getPlaceholder)})`,
1294
+ ),
1278
1295
  deleteRowIds,
1279
1296
  );
1280
1297
  } else if (
@@ -1282,9 +1299,7 @@ const getCommandFunctions = (
1282
1299
  collHas(schemaMap, tableName)
1283
1300
  ) {
1284
1301
  await executeCommand(
1285
- DELETE_FROM +
1286
- escapeId(tableName) +
1287
- getWhereCondition(tableName, condition),
1302
+ DELETE_FROM + escapeId(tableName) + getWhere(tableName, condition),
1288
1303
  );
1289
1304
  }
1290
1305
  }
@@ -110,50 +110,6 @@ const arrayClear = (array, to = size(array)) => array.splice(0, to);
110
110
  const arrayPush = (array, ...values) => array.push(...values);
111
111
  const arrayShift = (array) => array.shift();
112
112
 
113
- const SINGLE_ROW_ID = '_';
114
- const DEFAULT_ROW_ID_COLUMN_NAME = '_id';
115
- const SELECT = 'SELECT';
116
- const WHERE = 'WHERE';
117
- const TABLE = 'TABLE';
118
- const INSERT = 'INSERT';
119
- const DELETE = 'DELETE';
120
- const UPDATE = 'UPDATE';
121
- const ALTER_TABLE = 'ALTER ' + TABLE;
122
- const FROM = 'FROM';
123
- const DELETE_FROM = DELETE + ' ' + FROM;
124
- const SELECT_STAR_FROM = SELECT + '*' + FROM;
125
- const PRAGMA = 'pragma_';
126
- const DATA_VERSION = 'data_version';
127
- const SCHEMA_VERSION = 'schema_version';
128
- const PRAGMA_TABLE = 'pragma_table_';
129
- const CREATE = 'CREATE ';
130
- const CREATE_TABLE = CREATE + TABLE;
131
- const TABLE_NAME_PLACEHOLDER_REGEX = /\$tableName/g;
132
- const getWrappedCommand = (executeCommand, onSqlCommand) =>
133
- onSqlCommand
134
- ? async (sql, params) => {
135
- onSqlCommand(sql, params);
136
- return await executeCommand(sql, params);
137
- }
138
- : executeCommand;
139
- const escapeId = (str) =>
140
- arrayJoin(
141
- arrayMap(strSplit(str, DOT), (part) => `"${strReplace(part, /"/g, '""')}"`),
142
- DOT,
143
- );
144
- const escapeColumnNames = (...columnNames) =>
145
- arrayJoin(arrayMap(columnNames, escapeId), COMMA);
146
- const anonymousPlaceholder = () => '?';
147
- const getPlaceholders = (array, getPlaceholder, offset = [1]) =>
148
- arrayJoin(
149
- arrayMap(array, () => getPlaceholder(offset)),
150
- COMMA,
151
- );
152
- const getWhereCondition = (tableName, condition = TRUE) =>
153
- WHERE + `(${replaceTableName(condition, escapeId(tableName))})`;
154
- const replaceTableName = (condition, tableName) =>
155
- strReplace(condition, TABLE_NAME_PLACEHOLDER_REGEX, tableName);
156
-
157
113
  const object = Object;
158
114
  const getPrototypeOf = (obj) => object.getPrototypeOf(obj);
159
115
  const objEntries = object.entries;
@@ -203,6 +159,62 @@ const objValues = (obj) => object.values(obj);
203
159
  const objSize = (obj) => size(objIds(obj));
204
160
  const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
205
161
 
162
+ const SINGLE_ROW_ID = '_';
163
+ const DEFAULT_ROW_ID_COLUMN_NAME = '_id';
164
+ const SELECT = 'SELECT';
165
+ const WHERE = 'WHERE';
166
+ const TABLE = 'TABLE';
167
+ const INSERT = 'INSERT';
168
+ const DELETE = 'DELETE';
169
+ const UPDATE = 'UPDATE';
170
+ const ALTER_TABLE = 'ALTER ' + TABLE;
171
+ const FROM = 'FROM';
172
+ const DELETE_FROM = DELETE + ' ' + FROM;
173
+ const SELECT_STAR_FROM = SELECT + '*' + FROM;
174
+ const PRAGMA = 'pragma_';
175
+ const DATA_VERSION = 'data_version';
176
+ const SCHEMA_VERSION = 'schema_version';
177
+ const PRAGMA_TABLE = 'pragma_table_';
178
+ const CREATE = 'CREATE ';
179
+ const CREATE_TABLE = CREATE + TABLE;
180
+ const TABLE_NAME_PLACEHOLDER_REGEX = /\$tableName/g;
181
+ const getWrappedCommand = (executeCommand, onSqlCommand) =>
182
+ onSqlCommand
183
+ ? async (sql, params) => {
184
+ onSqlCommand(sql, params);
185
+ return await executeCommand(sql, params);
186
+ }
187
+ : executeCommand;
188
+ const escapeId = (str) =>
189
+ arrayJoin(
190
+ arrayMap(strSplit(str, DOT), (part) => `"${strReplace(part, /"/g, '""')}"`),
191
+ DOT,
192
+ );
193
+ const escapeColumnNames = (...columnNames) =>
194
+ arrayJoin(arrayMap(columnNames, escapeId), COMMA);
195
+ const anonymousPlaceholder = () => '?';
196
+ const getPlaceholders = (array, getPlaceholder, offset = [1]) =>
197
+ arrayJoin(
198
+ arrayMap(array, () => getPlaceholder(offset)),
199
+ COMMA,
200
+ );
201
+ const getWhere = (tableName, condition = TRUE, extraCondition) => {
202
+ const conditions = arrayFilter(
203
+ [
204
+ condition == TRUE
205
+ ? void 0
206
+ : `(${replaceTableName(condition, escapeId(tableName))})`,
207
+ extraCondition,
208
+ ],
209
+ (condition2) => !isUndefined(condition2),
210
+ );
211
+ return isEmpty(conditions)
212
+ ? EMPTY_STRING
213
+ : WHERE + arrayJoin(conditions, 'AND');
214
+ };
215
+ const replaceTableName = (condition, tableName) =>
216
+ strReplace(condition, TABLE_NAME_PLACEHOLDER_REGEX, tableName);
217
+
206
218
  const map = Map;
207
219
  const mapNew = (entries) => new map(entries);
208
220
  const mapGet = (map2, key) => map2?.get(key);
@@ -1050,7 +1062,7 @@ const getCommandFunctions = (
1050
1062
  await executeCommand(
1051
1063
  SELECT_STAR_FROM +
1052
1064
  escapeId(tableName) +
1053
- getWhereCondition(tableName, condition),
1065
+ getWhere(tableName, condition),
1054
1066
  ),
1055
1067
  (row) => {
1056
1068
  const rowId = row[rowIdColumnName];
@@ -1206,9 +1218,7 @@ const getCommandFunctions = (
1206
1218
  if (isUndefined(content)) {
1207
1219
  if (isUndefined(contentSubIdSet)) {
1208
1220
  await executeCommand(
1209
- DELETE_FROM +
1210
- escapeId(tableName) +
1211
- getWhereCondition(tableName, condition),
1221
+ DELETE_FROM + escapeId(tableName) + getWhere(tableName, condition),
1212
1222
  );
1213
1223
  }
1214
1224
  } else {
@@ -1218,8 +1228,11 @@ const getCommandFunctions = (
1218
1228
  await executeCommand(
1219
1229
  DELETE_FROM +
1220
1230
  escapeId(tableName) +
1221
- getWhereCondition(tableName, condition) +
1222
- `AND(${escapeId(rowIdColumnName)}=${getPlaceholder([1])})`,
1231
+ getWhere(
1232
+ tableName,
1233
+ condition,
1234
+ `(${escapeId(rowIdColumnName)}=${getPlaceholder([1])})`,
1235
+ ),
1223
1236
  [rowId],
1224
1237
  );
1225
1238
  } else if (!isEmpty(settingColumnNames)) {
@@ -1278,8 +1291,12 @@ const getCommandFunctions = (
1278
1291
  await executeCommand(
1279
1292
  DELETE_FROM +
1280
1293
  escapeId(tableName) +
1281
- getWhereCondition(tableName, condition) + // eslint-disable-next-line max-len
1282
- `AND${escapeId(rowIdColumnName)}NOT IN(${getPlaceholders(deleteRowIds, getPlaceholder)})`,
1294
+ getWhere(
1295
+ tableName,
1296
+ condition,
1297
+ // eslint-disable-next-line max-len
1298
+ `${escapeId(rowIdColumnName)}NOT IN(${getPlaceholders(deleteRowIds, getPlaceholder)})`,
1299
+ ),
1283
1300
  deleteRowIds,
1284
1301
  );
1285
1302
  } else if (
@@ -1287,9 +1304,7 @@ const getCommandFunctions = (
1287
1304
  collHas(schemaMap, tableName)
1288
1305
  ) {
1289
1306
  await executeCommand(
1290
- DELETE_FROM +
1291
- escapeId(tableName) +
1292
- getWhereCondition(tableName, condition),
1307
+ DELETE_FROM + escapeId(tableName) + getWhere(tableName, condition),
1293
1308
  );
1294
1309
  }
1295
1310
  }