@onyx.dev/onyx-database 0.1.7 → 0.2.0

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/README.md CHANGED
@@ -182,7 +182,7 @@ export interface UserProfile {
182
182
 
183
183
  const user = await db
184
184
  .from(tables.User)
185
- .selectFields('id', 'username')
185
+ .select('id', 'username')
186
186
  .resolve('roles.permissions', 'profile')
187
187
  .firstOrNull();
188
188
 
package/dist/index.cjs CHANGED
@@ -926,6 +926,17 @@ function clearCacheConfig() {
926
926
  function toSingleCondition(criteria) {
927
927
  return { conditionType: "SingleCondition", criteria };
928
928
  }
929
+ function flattenStrings(values) {
930
+ const flat = [];
931
+ for (const value of values) {
932
+ if (Array.isArray(value)) {
933
+ flat.push(...value);
934
+ } else if (typeof value === "string") {
935
+ flat.push(value);
936
+ }
937
+ }
938
+ return flat;
939
+ }
929
940
  function toCondition(input) {
930
941
  if (typeof input.toCondition === "function") {
931
942
  return input.toCondition();
@@ -1005,7 +1016,7 @@ var OnyxDatabaseImpl = class {
1005
1016
  null,
1006
1017
  this.defaultPartition
1007
1018
  );
1008
- qb.selectFields(...fields);
1019
+ qb.select(...fields);
1009
1020
  return qb;
1010
1021
  }
1011
1022
  cascade(...relationships) {
@@ -1212,13 +1223,13 @@ var QueryBuilderImpl = class {
1212
1223
  this.table = table;
1213
1224
  return this;
1214
1225
  }
1215
- selectFields(...fields) {
1216
- const flat = fields.flatMap((f) => Array.isArray(f) ? f : [f]);
1226
+ select(...fields) {
1227
+ const flat = flattenStrings(fields);
1217
1228
  this.fields = flat.length > 0 ? flat : null;
1218
1229
  return this;
1219
1230
  }
1220
1231
  resolve(...values) {
1221
- const flat = values.flatMap((v) => Array.isArray(v) ? v : [v]);
1232
+ const flat = flattenStrings(values);
1222
1233
  this.resolvers = flat.length > 0 ? flat : null;
1223
1234
  return this;
1224
1235
  }