remult 3.4.1 → 3.5.0-next.1

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 (68) hide show
  1. package/esm/internals.js +1 -0
  2. package/esm/postgres/postgres-data-provider.js +4 -5
  3. package/esm/remult-duckdb.js +4 -0
  4. package/esm/remult-knex/index.js +41 -9
  5. package/esm/remult-mongo.js +27 -9
  6. package/esm/remult-sqlite-core.js +4 -1
  7. package/esm/server/remult-api-server.js +1 -1
  8. package/esm/src/buildRestDataProvider.js +4 -2
  9. package/esm/src/data-api.js +2 -2
  10. package/esm/src/data-interfaces.js +2 -1
  11. package/esm/src/data-providers/array-entity-data-provider.js +5 -0
  12. package/esm/src/data-providers/rest-data-provider-using-fetch.js +2 -2
  13. package/esm/src/data-providers/retry.js +11 -6
  14. package/esm/src/data-providers/sql-database.js +41 -31
  15. package/esm/src/filter/entityDbName.js +6 -10
  16. package/esm/src/filter/fieldDbName.js +8 -14
  17. package/esm/src/filter/filter-consumer-bridge-to-sql-request.js +4 -4
  18. package/esm/src/filter/sqlExpressionInProgress.js +14 -0
  19. package/esm/src/live-query/SubscriptionChannel.js +13 -8
  20. package/esm/src/remult-static.js +1 -0
  21. package/esm/src/remult3/Fields.js +14 -14
  22. package/esm/src/remult3/QueryResultImpl.js +2 -0
  23. package/esm/src/remult3/RepositoryImplementation.js +47 -33
  24. package/esm/src/sort.js +18 -0
  25. package/index.d.ts +1 -1
  26. package/internals.d.ts +1 -0
  27. package/internals.js +3 -1
  28. package/package.json +41 -1
  29. package/postgres/postgres-data-provider.d.ts +2 -3
  30. package/postgres/postgres-data-provider.js +4 -4
  31. package/remult-duckdb.d.ts +2 -0
  32. package/remult-duckdb.js +4 -0
  33. package/remult-knex/index.d.ts +2 -0
  34. package/remult-knex/index.js +127 -80
  35. package/remult-mongo.js +29 -8
  36. package/remult-sqlite-core.d.ts +2 -1
  37. package/remult-sqlite-core.js +4 -0
  38. package/server/remult-api-server.d.ts +12 -1
  39. package/server/remult-api-server.js +1 -1
  40. package/src/buildRestDataProvider.js +3 -1
  41. package/src/column-interfaces.d.ts +5 -1
  42. package/src/data-api.js +2 -2
  43. package/src/data-interfaces.d.ts +0 -1
  44. package/src/data-interfaces.js +3 -0
  45. package/src/data-providers/array-entity-data-provider.js +5 -0
  46. package/src/data-providers/rest-data-provider-using-fetch.js +1 -1
  47. package/src/data-providers/retry.d.ts +4 -1
  48. package/src/data-providers/retry.js +26 -16
  49. package/src/data-providers/sql-database.d.ts +7 -3
  50. package/src/data-providers/sql-database.js +100 -84
  51. package/src/filter/entityDbName.d.ts +1 -1
  52. package/src/filter/entityDbName.js +14 -16
  53. package/src/filter/fieldDbName.js +19 -25
  54. package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +1 -1
  55. package/src/filter/filter-consumer-bridge-to-sql-request.js +7 -5
  56. package/src/filter/sqlExpressionInProgress.d.ts +2 -0
  57. package/src/filter/sqlExpressionInProgress.js +27 -0
  58. package/src/live-query/SubscriptionChannel.js +16 -10
  59. package/src/remult-static.d.ts +2 -0
  60. package/src/remult-static.js +1 -0
  61. package/src/remult3/Fields.d.ts +5 -3
  62. package/src/remult3/Fields.js +24 -13
  63. package/src/remult3/QueryResultImpl.js +2 -0
  64. package/src/remult3/RepositoryImplementation.js +284 -272
  65. package/src/remult3/remult3.d.ts +6 -1
  66. package/src/sort.d.ts +19 -0
  67. package/src/sort.js +20 -1
  68. package/src/sql-command.d.ts +2 -1
@@ -0,0 +1,14 @@
1
+ const sqlExpressionInProgressKey = Symbol.for(`sqlExpressionInProgressKey`);
2
+ export function isSqlExpressionInProgress(owner) {
3
+ return owner[sqlExpressionInProgressKey];
4
+ }
5
+ export async function runSqlExpression(owner, sqlExpression) {
6
+ try {
7
+ ;
8
+ owner[sqlExpressionInProgressKey] = true;
9
+ return await sqlExpression();
10
+ }
11
+ finally {
12
+ delete owner[sqlExpressionInProgressKey];
13
+ }
14
+ }
@@ -39,12 +39,6 @@ export class LiveQuerySubscriber {
39
39
  forListeners(what, changes) {
40
40
  what((reducer) => {
41
41
  this.defaultQueryState = reducer(this.defaultQueryState);
42
- if (changes.find((c) => c.type === 'add' || c.type === 'replace')) {
43
- if (this.query.options.orderBy) {
44
- const o = Sort.translateOrderByToSort(this.repo.metadata, this.query.options.orderBy);
45
- this.defaultQueryState.sort((a, b) => o.compare(a, b));
46
- }
47
- }
48
42
  });
49
43
  for (const l of this.listeners) {
50
44
  what((reducer) => {
@@ -88,7 +82,7 @@ export class LiveQuerySubscriber {
88
82
  }
89
83
  }
90
84
  this.forListeners((listener) => {
91
- listener((items) => {
85
+ listener((items, { pos = 'auto' } = {}) => {
92
86
  if (!items)
93
87
  items = [];
94
88
  for (const message of data) {
@@ -105,13 +99,24 @@ export class LiveQuerySubscriber {
105
99
  case 'add':
106
100
  items = items.filter((x) => this.repo.metadata.idMetadata.getId(x) !==
107
101
  this.repo.metadata.idMetadata.getId(message.data.item));
108
- items.push(message.data.item);
102
+ if (pos === 'first')
103
+ items.unshift(message.data.item);
104
+ else
105
+ items.push(message.data.item);
109
106
  break;
110
107
  case 'remove':
111
108
  items = items.filter((x) => this.repo.metadata.idMetadata.getId(x) !== message.data.id);
112
109
  break;
113
110
  }
114
111
  }
112
+ const orderBy = this.query.options.orderBy ??
113
+ this.repo.metadata.options.defaultOrderBy;
114
+ if (pos === 'auto' &&
115
+ orderBy &&
116
+ data.some((m) => m.type === 'add' || m.type === 'replace')) {
117
+ const o = Sort.translateOrderByToSort(this.repo.metadata, orderBy);
118
+ items.sort((a, b) => o.compare(a, b));
119
+ }
115
120
  return items;
116
121
  });
117
122
  }, data);
@@ -20,6 +20,7 @@ let x = {
20
20
  },
21
21
  fieldOptionsEnricher: undefined,
22
22
  labelTransformer: undefined,
23
+ nullSort: undefined,
23
24
  defaultIdFactory: undefined,
24
25
  defaultDataProvider: () => undefined,
25
26
  };
@@ -63,6 +63,8 @@ export class Fields {
63
63
  static createdAt(...options) {
64
64
  return Field(() => Date, {
65
65
  allowApiUpdate: false,
66
+ // Set on every insert, so never NULL.
67
+ allowNull: false,
66
68
  saving: (_, ref, { isNew }) => {
67
69
  if (isNew)
68
70
  ref.value = new Date();
@@ -72,6 +74,8 @@ export class Fields {
72
74
  static updatedAt(...options) {
73
75
  return Field(() => Date, {
74
76
  allowApiUpdate: false,
77
+ // Set on every save, so never NULL.
78
+ allowNull: false,
75
79
  saving: (_, ref) => {
76
80
  ref.value = new Date();
77
81
  },
@@ -79,10 +83,7 @@ export class Fields {
79
83
  }
80
84
  /** @deprecated use `@Fields.id()` instead */
81
85
  static uuid(...options) {
82
- return Fields.id({
83
- idFactory: () => crypto.randomUUID(),
84
- ...options,
85
- });
86
+ return Fields.id({ idFactory: () => crypto.randomUUID() }, ...options);
86
87
  }
87
88
  /**
88
89
  * ### cuid
@@ -143,20 +144,19 @@ export class Fields {
143
144
  * }
144
145
  * ```
145
146
  */
146
- static id(options) {
147
+ static id(...options) {
148
+ // Read once the options are merged, so a later option or a function option can set it.
149
+ let idFactory;
150
+ const newId = () => (idFactory ?? Fields.defaultIdFactory)();
147
151
  return Field(() => String, {
148
152
  allowApiUpdate: false,
149
- defaultValue: () => {
150
- let idFactory = options?.idFactory ?? Fields.defaultIdFactory;
151
- return idFactory();
152
- },
153
+ defaultValue: newId,
153
154
  saving: (_, r) => {
154
- if (!r.value) {
155
- let idFactory = options?.idFactory ?? Fields.defaultIdFactory;
156
- r.value = idFactory();
157
- }
155
+ if (!r.value)
156
+ r.value = newId();
158
157
  },
159
- ...options,
158
+ }, ...options, (o) => {
159
+ idFactory = o.idFactory;
160
160
  });
161
161
  }
162
162
  /**
@@ -26,6 +26,7 @@ export class QueryResultImpl {
26
26
  page: page,
27
27
  load: this.options.load,
28
28
  include: this.options.include,
29
+ args: this.options.args,
29
30
  });
30
31
  }
31
32
  async count() {
@@ -51,6 +52,7 @@ export class QueryResultImpl {
51
52
  limit: this.options.pageSize,
52
53
  load: this.options.load,
53
54
  include: this.options.include,
55
+ args: this.options.args,
54
56
  };
55
57
  let getItems = () => this.repo.find(options);
56
58
  if (this._aggregates === undefined &&
@@ -2,7 +2,7 @@ import { LookupColumn, makeTitle } from '../column.js';
2
2
  import { CompoundIdField } from '../CompoundIdField.js';
3
3
  import { Remult } from '../context.js';
4
4
  import { Filter } from '../filter/filter-interfaces.js';
5
- import { Sort } from '../sort.js';
5
+ import { Sort, isNullFirstSort } from '../sort.js';
6
6
  import { GroupByCountMember, GroupByForApiKey, } from './remult3.js';
7
7
  import { assign } from '../../assign.js';
8
8
  import { EntityError, } from '../data-interfaces.js';
@@ -57,37 +57,31 @@ export class RepositoryImplementation {
57
57
  return this;
58
58
  }
59
59
  async _createAfterFilter(orderBy, lastRow) {
60
- let values = new Map();
61
- for (const s of Sort.translateOrderByToSort(this.metadata, orderBy)
62
- .Segments) {
63
- let existingVal = lastRow[s.field.key];
64
- // if (typeof existingVal !== "string" && typeof existingVal !== "number") {
65
- // }
66
- // else {
67
- // let ei = getEntitySettings(s.field.valueType, false);
68
- // if (ei) {
69
- // existingVal = await this.remult.repo(s.field.valueType).findId(existingVal);
70
- // }
71
- // }
72
- values.set(s.field.key, existingVal);
73
- }
74
- let r = { $or: [] };
75
- let equalToColumn = [];
76
- for (const s of Sort.translateOrderByToSort(this.metadata, orderBy)
77
- .Segments) {
78
- let f = {};
79
- for (const c of equalToColumn) {
80
- f[c.key] = values.get(c.key);
81
- }
82
- equalToColumn.push(s.field);
83
- if (s.isDescending) {
84
- f[s.field.key] = { $lt: values.get(s.field.key) };
60
+ const ref = this.getEntityRef(lastRow);
61
+ const filter = { $or: [] };
62
+ const or = filter.$or;
63
+ let equal = {};
64
+ for (const { field, isDescending } of Sort.translateOrderByToSort(this.metadata, orderBy).Segments) {
65
+ // A string key cannot name an entity member for TypeScript.
66
+ const keyIs = (condition) => ({ [field.key]: condition });
67
+ // An unloaded relation reads `undefined`, its id is there.
68
+ const value = ref.fields.find(field.key).getId() ?? null;
69
+ const nullFirst = isNullFirstSort(isDescending);
70
+ if (value === null) {
71
+ if (nullFirst)
72
+ or.push({ ...equal, $not: keyIs(null) });
85
73
  }
86
- else
87
- f[s.field.key] = { $gt: values.get(s.field.key) };
88
- r.$or.push(f);
74
+ else {
75
+ or.push({
76
+ ...equal,
77
+ ...keyIs(isDescending ? { $lt: value } : { $gt: value }),
78
+ });
79
+ if (field.allowNull && !nullFirst)
80
+ or.push({ ...equal, ...keyIs(null) });
81
+ }
82
+ equal = { ...equal, ...keyIs(value) };
89
83
  }
90
- return r;
84
+ return filter;
91
85
  }
92
86
  relations(item) {
93
87
  return new Proxy({}, {
@@ -760,7 +754,9 @@ export class RepositoryImplementation {
760
754
  }
761
755
  else {
762
756
  for (const row of result) {
763
- Reflect.deleteProperty(row, col.key);
757
+ // Deleting the relation's accessor would drop its change tracking, so only a plain value goes.
758
+ if (!Object.getOwnPropertyDescriptor(row, col.key)?.get)
759
+ Reflect.deleteProperty(row, col.key);
764
760
  }
765
761
  }
766
762
  }
@@ -1799,7 +1795,8 @@ export class rowHelperImplementation extends rowHelperBase {
1799
1795
  if (!this.repo._dataProvider.isProxy)
1800
1796
  //y2 should be changed to be based on data provider - consider naming
1801
1797
  for (const col of this.info.fieldsMetadata) {
1802
- if (col.options.serverExpression) {
1798
+ if (col.options.serverExpression &&
1799
+ !this._fieldsExcludedBySelect?.has(col.key)) {
1803
1800
  const result = (await col.options.serverExpression(this.instance));
1804
1801
  if (result !== undefined)
1805
1802
  this.instance[col.key] = result;
@@ -2117,6 +2114,19 @@ export function buildLabel(label, key, remult, metaData) {
2117
2114
  return makeTitle(key);
2118
2115
  return '';
2119
2116
  }
2117
+ /** Migrations give the column a default value (`''`, `0`, `false`), so it is `not null`. */
2118
+ function hasColumnDefault({ valueType, valueConverter, }) {
2119
+ if (valueType === Number || valueType === Boolean)
2120
+ return true;
2121
+ if (valueType === Date)
2122
+ return false;
2123
+ // A relation id is an integer or a string, and its fieldTypeInDb would load the related entity.
2124
+ if (getEntitySettings(valueType, false))
2125
+ return true;
2126
+ const type = valueConverter?.fieldTypeInDb;
2127
+ // None is a string column, default ''. `dbid` is a Mongo ObjectId marker, not a column type.
2128
+ return !type || type === 'dbid' || type === 'integer';
2129
+ }
2120
2130
  export class columnDefsImpl {
2121
2131
  settings;
2122
2132
  entityDefs;
@@ -2149,7 +2159,7 @@ export class columnDefsImpl {
2149
2159
  return result;
2150
2160
  },
2151
2161
  });
2152
- this.allowNull = !!this.settings.allowNull;
2162
+ this.allowNull = this.settings.allowNull ?? !hasColumnDefault(settings);
2153
2163
  this.valueType = this.settings.valueType;
2154
2164
  this.key = this.settings.key;
2155
2165
  this.inputType = this.settings.inputType;
@@ -2275,6 +2285,10 @@ class EntityFullInfo {
2275
2285
  else
2276
2286
  this.idMetadata.field = [...this.fields][0];
2277
2287
  }
2288
+ // The database rejects NULL in a primary key.
2289
+ for (const f of this.idMetadata.fields)
2290
+ if (f)
2291
+ f.allowNull = f.options.allowNull ?? false;
2278
2292
  }
2279
2293
  apiUpdateAllowed(item) {
2280
2294
  if (this.options.allowApiUpdate === undefined)
package/esm/src/sort.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { remultStatic } from './remult-static.js';
1
2
  import { getRelationFieldInfo } from './remult3/relationInfoMember.js';
2
3
  /**
3
4
  * The `Sort` class is used to describe sorting criteria for queries. It is mainly used internally,
@@ -161,9 +162,26 @@ export class Sort {
161
162
  return orderBy;
162
163
  }
163
164
  }
165
+ /**
166
+ * Where NULL sorts, for the whole app: set it on both the server and the client.
167
+ * @see https://remult.dev/docs/field-types#where-null-sorts
168
+ */
169
+ export const NullSort = remultStatic.nullSort || (remultStatic.nullSort = { order: 'native' });
170
+ /** Remult's own order, without a database: `native` is NULL lowest. */
171
+ export function isNullFirstSort(isDescending) {
172
+ if (NullSort.order === 'native')
173
+ return !isDescending;
174
+ return NullSort.order[isDescending ? 'desc' : 'asc'] === 'NULLS FIRST';
175
+ }
164
176
  export function compareForSort(left, right, descending) {
165
177
  left = fixValueForSort(left);
166
178
  right = fixValueForSort(right);
179
+ // `null > 'a'` and `null < 'a'` are both false, which is not an order.
180
+ if (left == null || right == null) {
181
+ if (left == right)
182
+ return 0;
183
+ return (left == null) === isNullFirstSort(descending) ? -1 : 1;
184
+ }
167
185
  let r = 0;
168
186
  if (left > right)
169
187
  r = 1;
package/index.d.ts CHANGED
@@ -45,7 +45,7 @@ export { Allow, Remult, withRemult, isBackend, EventSource, } from './src/contex
45
45
  export type { Allowed, RemultContext, ApiClient, AllowedForInstance, EventDispatcher, UserInfo, } from './src/context.js';
46
46
  export type { ExternalHttpProvider } from './src/buildRestDataProvider.js';
47
47
  export { Sort } from './src/sort.js';
48
- export type { SortSegment } from './src/sort.js';
48
+ export type { SortSegment, NativeNullSort, NullOrder } from './src/sort.js';
49
49
  export { CompoundIdField } from './src/CompoundIdField.js';
50
50
  export { Filter } from './src/filter/filter-interfaces.js';
51
51
  export type { FilterConsumer, FilterPreciseValues, } from './src/filter/filter-interfaces.js';
package/internals.d.ts CHANGED
@@ -18,6 +18,7 @@ export type { ClassType } from './classType.js';
18
18
  export type { SubscriptionServerRouteApi, SubscriptionServerRouteHandlerArgs, } from './server/remult-api-server.js';
19
19
  export type { DataApiResponse } from './src/data-api.js';
20
20
  export { flags } from './src/remult3/remult3.js';
21
+ export { NullSort } from './src/sort.js';
21
22
  export { SseSubscriptionClient } from './src/live-query/SseSubscriptionClient.js';
22
23
  export { DataProviderPromiseWrapper } from './src/data-interfaces.js';
23
24
  export { pagedQueryResult } from './src/remult3/pagedQueryResult.js';
package/internals.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pagedQueryResult = exports.DataProviderPromiseWrapper = exports.SseSubscriptionClient = exports.flags = exports.isOfType = exports.actionInfo = exports.walkFilter = exports.omitFilterField = exports.__updateEntityBasedOnWhere = exports.getEntitySettings = exports.fieldOptionsEnricher = exports.getControllerRef = exports.controllerRefImpl = exports.decorateColumnSettings = exports.getRelationFieldInfo = exports.getRelationInfo = exports.sqlRelationsFilter = exports.sqlRelations = void 0;
3
+ exports.pagedQueryResult = exports.DataProviderPromiseWrapper = exports.SseSubscriptionClient = exports.NullSort = exports.flags = exports.isOfType = exports.actionInfo = exports.walkFilter = exports.omitFilterField = exports.__updateEntityBasedOnWhere = exports.getEntitySettings = exports.fieldOptionsEnricher = exports.getControllerRef = exports.controllerRefImpl = exports.decorateColumnSettings = exports.getRelationFieldInfo = exports.getRelationInfo = exports.sqlRelationsFilter = exports.sqlRelations = void 0;
4
4
  var remult_static_js_1 = require("./src/remult-static.js");
5
5
  var sql_relations_js_1 = require("./src/data-providers/sql-relations.js");
6
6
  Object.defineProperty(exports, "sqlRelations", { enumerable: true, get: function () { return sql_relations_js_1.sqlRelations; } });
@@ -25,6 +25,8 @@ var isOfType_js_1 = require("./src/isOfType.js");
25
25
  Object.defineProperty(exports, "isOfType", { enumerable: true, get: function () { return isOfType_js_1.isOfType; } });
26
26
  var remult3_js_1 = require("./src/remult3/remult3.js");
27
27
  Object.defineProperty(exports, "flags", { enumerable: true, get: function () { return remult3_js_1.flags; } });
28
+ var sort_js_1 = require("./src/sort.js");
29
+ Object.defineProperty(exports, "NullSort", { enumerable: true, get: function () { return sort_js_1.NullSort; } });
28
30
  var SseSubscriptionClient_js_1 = require("./src/live-query/SseSubscriptionClient.js");
29
31
  Object.defineProperty(exports, "SseSubscriptionClient", { enumerable: true, get: function () { return SseSubscriptionClient_js_1.SseSubscriptionClient; } });
30
32
  var data_interfaces_js_1 = require("./src/data-interfaces.js");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "3.4.1",
3
+ "version": "3.5.0-next.1",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "homepage": "https://remult.dev",
6
6
  "repository": {
@@ -26,6 +26,46 @@
26
26
  "dependencies": {
27
27
  "tslib": "^2.3.1"
28
28
  },
29
+ "peerDependencies": {
30
+ "@duckdb/node-api": ">=1.3.2-alpha.26",
31
+ "@libsql/client": ">=0.5.6",
32
+ "better-sqlite3": ">=12.2.0",
33
+ "cloudflare": ">=4.4.1",
34
+ "knex": ">=2.4.0",
35
+ "mongodb": ">=4.17.1",
36
+ "pg": ">=8.3.0",
37
+ "sql.js": ">=1.9.0",
38
+ "sqlite3": ">=5.1.7"
39
+ },
40
+ "peerDependenciesMeta": {
41
+ "@duckdb/node-api": {
42
+ "optional": true
43
+ },
44
+ "@libsql/client": {
45
+ "optional": true
46
+ },
47
+ "better-sqlite3": {
48
+ "optional": true
49
+ },
50
+ "cloudflare": {
51
+ "optional": true
52
+ },
53
+ "knex": {
54
+ "optional": true
55
+ },
56
+ "mongodb": {
57
+ "optional": true
58
+ },
59
+ "pg": {
60
+ "optional": true
61
+ },
62
+ "sql.js": {
63
+ "optional": true
64
+ },
65
+ "sqlite3": {
66
+ "optional": true
67
+ }
68
+ },
29
69
  "exports": {
30
70
  ".": {
31
71
  "require": "./index.js",
@@ -1,6 +1,7 @@
1
1
  import type { ClientBase, PoolConfig, QueryResult } from 'pg';
2
2
  import { SqlDatabase } from '../src/data-providers/sql-database.js';
3
3
  import type { EntityMetadata } from '../src/remult3/remult3.js';
4
+ import type { NativeNullSort } from '../src/sort.js';
4
5
  import type { SqlCommand, SqlImplementation } from '../src/sql-command.js';
5
6
  import type { CanBuildMigrations, MigrationBuilder, MigrationCode } from '../migrations/migration-types.js';
6
7
  import type { DataProvider } from '../index.js';
@@ -23,13 +24,12 @@ export declare class PostgresDataProvider implements SqlImplementation, CanBuild
23
24
  wrapIdentifier?: (name: string) => string;
24
25
  caseInsensitiveIdentifiers?: boolean;
25
26
  schema?: string;
26
- orderByNullsFirst?: boolean;
27
27
  } | undefined);
28
28
  end(): Promise<void>;
29
29
  provideMigrationBuilder(builder: MigrationCode): MigrationBuilder;
30
30
  wrapIdentifier: (name: string) => string;
31
31
  ensureSchema(entities: EntityMetadata<any>[]): Promise<void>;
32
- orderByNullsFirst?: boolean;
32
+ nativeNullSort: NativeNullSort;
33
33
  transaction(action: (dataProvider: SqlImplementation) => Promise<void>): Promise<void>;
34
34
  }
35
35
  export interface PostgresCommandSource {
@@ -43,7 +43,6 @@ export declare function createPostgresDataProvider(options?: {
43
43
  wrapIdentifier?: (name: string) => string;
44
44
  caseInsensitiveIdentifiers?: boolean;
45
45
  schema?: string;
46
- orderByNullsFirst?: boolean;
47
46
  }): Promise<SqlDatabase>;
48
47
  export declare function preparePostgresQueueStorage(sql: SqlDatabase): Promise<import("../server/remult-api-server.js").EntityQueueStorage>;
49
48
  export declare class PostgresSchemaWrapper implements PostgresPool {
@@ -24,12 +24,14 @@ var PostgresDataProvider = /** @class */ (function () {
24
24
  })
25
25
  .join('.');
26
26
  };
27
+ this.nativeNullSort = {
28
+ order: { asc: 'NULLS LAST', desc: 'NULLS FIRST' },
29
+ syntax: 'NULLS FIRST/LAST',
30
+ };
27
31
  if (options === null || options === void 0 ? void 0 : options.wrapIdentifier)
28
32
  this.wrapIdentifier = options.wrapIdentifier;
29
33
  if (!(options === null || options === void 0 ? void 0 : options.wrapIdentifier) && (options === null || options === void 0 ? void 0 : options.caseInsensitiveIdentifiers))
30
34
  this.wrapIdentifier = function (name) { return name; };
31
- if (options === null || options === void 0 ? void 0 : options.orderByNullsFirst)
32
- this.orderByNullsFirst = options.orderByNullsFirst;
33
35
  if (options === null || options === void 0 ? void 0 : options.schema) {
34
36
  this.pool = new PostgresSchemaWrapper(pool, options.schema);
35
37
  }
@@ -134,7 +136,6 @@ var PostgresDataProvider = /** @class */ (function () {
134
136
  //@ts-ignore
135
137
  pool: client,
136
138
  wrapIdentifier: this.wrapIdentifier,
137
- orderByNullsFirst: this.orderByNullsFirst,
138
139
  })];
139
140
  case 4:
140
141
  _a.sent();
@@ -233,7 +234,6 @@ function createPostgresDataProvider(options) {
233
234
  wrapIdentifier: options.wrapIdentifier,
234
235
  caseInsensitiveIdentifiers: options.caseInsensitiveIdentifiers,
235
236
  schema: options.schema,
236
- orderByNullsFirst: options.orderByNullsFirst,
237
237
  }));
238
238
  return [2 /*return*/, db];
239
239
  });
@@ -1,9 +1,11 @@
1
1
  import type { DuckDBConnection } from '@duckdb/node-api';
2
2
  import { SqliteCoreDataProvider } from './remult-sqlite-core.js';
3
+ import type { NativeNullSort } from './src/sort.js';
3
4
  import { type FieldMetadata, type EntityMetadata } from './index.js';
4
5
  export declare class DuckDBDataProvider extends SqliteCoreDataProvider {
5
6
  private connection;
6
7
  constructor(connection: DuckDBConnection);
8
+ nativeNullSort: NativeNullSort;
7
9
  wrapIdentifier(name: string): string;
8
10
  getCreateTableSql(entity: EntityMetadata<any>): Promise<string[]>;
9
11
  addColumnSqlSyntax(x: FieldMetadata, dbName: string, isAlterColumn: boolean): string;
package/remult-duckdb.js CHANGED
@@ -14,6 +14,10 @@ var DuckDBDataProvider = /** @class */ (function (_super) {
14
14
  return [2 /*return*/, this.connection.disconnectSync()];
15
15
  }); }); }, false, true) || this;
16
16
  _this.connection = connection;
17
+ _this.nativeNullSort = {
18
+ order: { asc: 'NULLS LAST', desc: 'NULLS LAST' },
19
+ syntax: 'NULLS FIRST/LAST',
20
+ };
17
21
  return _this;
18
22
  }
19
23
  DuckDBDataProvider.prototype.wrapIdentifier = function (name) {
@@ -4,6 +4,7 @@ import type { FieldMetadata } from '../src/column-interfaces.js';
4
4
  import type { DataProvider, EntityDataProvider } from '../src/data-interfaces.js';
5
5
  import type { EntityFilter, EntityMetadata } from '../src/remult3/remult3.js';
6
6
  import type { RepositoryOverloads } from '../src/remult3/RepositoryImplementation.js';
7
+ import { type NativeNullSort } from '../src/sort.js';
7
8
  import type { HasJsonColumnStorage, HasWrapIdentifier, JsonColumnStorage, SqlCommand, SqlCommandFactory, SqlResult } from '../src/sql-command.js';
8
9
  import type { CanBuildMigrations, MigrationBuilder, MigrationCode } from '../migrations/migration-types.js';
9
10
  export declare class KnexDataProvider implements DataProvider, HasWrapIdentifier, HasJsonColumnStorage, SqlCommandFactory, CanBuildMigrations {
@@ -15,6 +16,7 @@ export declare class KnexDataProvider implements DataProvider, HasWrapIdentifier
15
16
  execute(sql: string): Promise<SqlResult>;
16
17
  static getDb(dataProvider?: DataProvider): Knex<any, any[]>;
17
18
  wrapIdentifier: (name: string) => string;
19
+ get nativeNullSort(): NativeNullSort;
18
20
  get jsonColumnStorage(): JsonColumnStorage;
19
21
  getEntityDataProvider(entity: EntityMetadata<any>): EntityDataProvider;
20
22
  transaction(action: (dataProvider: DataProvider) => Promise<void>): Promise<void>;