@nextlyhq/adapter-drizzle 0.0.2-alpha.46 → 0.0.2-alpha.48

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.
@@ -1,6 +1,6 @@
1
- import { AnyRelations } from 'drizzle-orm';
1
+ import { AnyRelations, SQL } from 'drizzle-orm';
2
2
  import { S as SupportedDialect, a as SqlParam, T as TableResolver } from './core-CVO7WYDj.cjs';
3
- import { T as TransactionContext, e as TransactionOptions, D as DatabaseCapabilities, P as PoolStats, S as SelectOptions, I as InsertOptions, W as WhereClause, U as UpdateOptions, f as DeleteOptions, g as UpsertOptions, a as Migration, d as MigrationResult } from './migration-B41DME-y.cjs';
3
+ import { T as TransactionContext, e as TransactionOptions, D as DatabaseCapabilities, P as PoolStats, S as SelectOptions, I as InsertOptions, W as WhereClause, U as UpdateOptions, f as DeleteOptions, g as UpsertOptions, a as Migration, d as MigrationResult } from './migration-BUc56kip.cjs';
4
4
  import { T as TableDefinition, C as CreateTableOptions, D as DropTableOptions, A as AlterTableOperation, a as AlterTableOptions } from './schema-BDn8WfSL.cjs';
5
5
  import { D as DatabaseErrorKind, a as DatabaseError } from './error-um1d_3Uo.cjs';
6
6
 
@@ -122,6 +122,27 @@ declare abstract class DrizzleAdapter {
122
122
  * Returns null if no resolver is set or table is not found.
123
123
  */
124
124
  protected getTableObject(tableName: string): unknown;
125
+ /**
126
+ * Run a Drizzle-built statement and return its rows.
127
+ *
128
+ * @remarks
129
+ * The CRUD methods resolve their table through the schema registry and reject
130
+ * any name it does not declare, which leaves no way to read from a table the
131
+ * ORM does not know — one mid-rename, above all — except by assembling SQL and
132
+ * quoting identifiers by hand. This takes Drizzle's `sql` template instead, so
133
+ * the dialect in use decides the quoting and the parameter binding.
134
+ *
135
+ * Concrete rather than abstract so existing adapters keep working unchanged.
136
+ * The three drivers disagree about both the call and the result: node-postgres
137
+ * returns `{ rows }`, mysql2 a `[rows, fields]` tuple, and better-sqlite3 has
138
+ * no `execute` at all and answers `all`. Keeping that here rather than at each
139
+ * call site is the point — a caller reasoning about it would be reasoning
140
+ * about a driver it cannot see.
141
+ *
142
+ * @param statement - Drizzle `sql` template to run
143
+ * @returns Rows the statement produced
144
+ */
145
+ queryStatement<T = Record<string, unknown>>(statement: SQL): Promise<T[]>;
125
146
  /**
126
147
  * Map data keys from SQL column names (snake_case) to Drizzle JS property names (camelCase).
127
148
  * Drizzle schemas define columns as e.g. `createdAt: timestamp("created_at")` — the JS
@@ -1,6 +1,6 @@
1
- import { AnyRelations } from 'drizzle-orm';
1
+ import { AnyRelations, SQL } from 'drizzle-orm';
2
2
  import { S as SupportedDialect, a as SqlParam, T as TableResolver } from './core-CVO7WYDj.js';
3
- import { T as TransactionContext, e as TransactionOptions, D as DatabaseCapabilities, P as PoolStats, S as SelectOptions, I as InsertOptions, W as WhereClause, U as UpdateOptions, f as DeleteOptions, g as UpsertOptions, a as Migration, d as MigrationResult } from './migration-XV8CXMZT.js';
3
+ import { T as TransactionContext, e as TransactionOptions, D as DatabaseCapabilities, P as PoolStats, S as SelectOptions, I as InsertOptions, W as WhereClause, U as UpdateOptions, f as DeleteOptions, g as UpsertOptions, a as Migration, d as MigrationResult } from './migration-Bj84e15B.js';
4
4
  import { T as TableDefinition, C as CreateTableOptions, D as DropTableOptions, A as AlterTableOperation, a as AlterTableOptions } from './schema-BIQ0YQZ_.js';
5
5
  import { D as DatabaseErrorKind, a as DatabaseError } from './error-um1d_3Uo.js';
6
6
 
@@ -122,6 +122,27 @@ declare abstract class DrizzleAdapter {
122
122
  * Returns null if no resolver is set or table is not found.
123
123
  */
124
124
  protected getTableObject(tableName: string): unknown;
125
+ /**
126
+ * Run a Drizzle-built statement and return its rows.
127
+ *
128
+ * @remarks
129
+ * The CRUD methods resolve their table through the schema registry and reject
130
+ * any name it does not declare, which leaves no way to read from a table the
131
+ * ORM does not know — one mid-rename, above all — except by assembling SQL and
132
+ * quoting identifiers by hand. This takes Drizzle's `sql` template instead, so
133
+ * the dialect in use decides the quoting and the parameter binding.
134
+ *
135
+ * Concrete rather than abstract so existing adapters keep working unchanged.
136
+ * The three drivers disagree about both the call and the result: node-postgres
137
+ * returns `{ rows }`, mysql2 a `[rows, fields]` tuple, and better-sqlite3 has
138
+ * no `execute` at all and answers `all`. Keeping that here rather than at each
139
+ * call site is the point — a caller reasoning about it would be reasoning
140
+ * about a driver it cannot see.
141
+ *
142
+ * @param statement - Drizzle `sql` template to run
143
+ * @returns Rows the statement produced
144
+ */
145
+ queryStatement<T = Record<string, unknown>>(statement: SQL): Promise<T[]>;
125
146
  /**
126
147
  * Map data keys from SQL column names (snake_case) to Drizzle JS property names (camelCase).
127
148
  * Drizzle schemas define columns as e.g. `createdAt: timestamp("created_at")` — the JS
package/dist/index.cjs CHANGED
@@ -151,6 +151,45 @@ var DrizzleAdapter = class {
151
151
  getTableObject(tableName) {
152
152
  return this.tableResolver?.getTable(tableName) ?? null;
153
153
  }
154
+ /**
155
+ * Run a Drizzle-built statement and return its rows.
156
+ *
157
+ * @remarks
158
+ * The CRUD methods resolve their table through the schema registry and reject
159
+ * any name it does not declare, which leaves no way to read from a table the
160
+ * ORM does not know — one mid-rename, above all — except by assembling SQL and
161
+ * quoting identifiers by hand. This takes Drizzle's `sql` template instead, so
162
+ * the dialect in use decides the quoting and the parameter binding.
163
+ *
164
+ * Concrete rather than abstract so existing adapters keep working unchanged.
165
+ * The three drivers disagree about both the call and the result: node-postgres
166
+ * returns `{ rows }`, mysql2 a `[rows, fields]` tuple, and better-sqlite3 has
167
+ * no `execute` at all and answers `all`. Keeping that here rather than at each
168
+ * call site is the point — a caller reasoning about it would be reasoning
169
+ * about a driver it cannot see.
170
+ *
171
+ * @param statement - Drizzle `sql` template to run
172
+ * @returns Rows the statement produced
173
+ */
174
+ async queryStatement(statement) {
175
+ if (this.getCapabilities().dialect === "sqlite") {
176
+ const db2 = this.getDrizzle();
177
+ return await db2.all(statement);
178
+ }
179
+ const db = this.getDrizzle();
180
+ const result = await db.execute(statement);
181
+ if (Array.isArray(result)) {
182
+ return Array.isArray(result[0]) ? result[0] : result;
183
+ }
184
+ if (typeof result === "object" && result !== null && Array.isArray(result.rows)) {
185
+ return result.rows;
186
+ }
187
+ throw this.createDatabaseError(
188
+ "query",
189
+ "Drizzle statement returned a result shape this adapter does not recognise; refusing to report it as an empty result.",
190
+ void 0
191
+ );
192
+ }
154
193
  /**
155
194
  * Map data keys from SQL column names (snake_case) to Drizzle JS property names (camelCase).
156
195
  * Drizzle schemas define columns as e.g. `createdAt: timestamp("created_at")` — the JS