MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / fromDrizzle

Function fromDrizzle

packages/core/fumadb/src/adapters/drizzle/query.ts:169–432  ·  view source on GitHub ↗
(
  schema: AnySchema,
  _db: unknown,
  provider: SQLProvider,
  interactiveTransactions: boolean = true,
  maxBoundParameters?: number
)

Source from the content-addressed store, hash-verified

167 * Require drizzle query mode, make sure to configure it first. (including the `schema` option)
168 */
169export function fromDrizzle(
170 schema: AnySchema,
171 _db: unknown,
172 provider: SQLProvider,
173 interactiveTransactions: boolean = true,
174 maxBoundParameters?: number
175): AbstractQuery<AnySchema> {
176 const [db, drizzleTables] = parseDrizzle(_db);
177
178 async function executeRaw(statement: string) {
179 const target = db as unknown as {
180 run?: (query: Drizzle.SQL) => unknown;
181 execute?: (query: Drizzle.SQL) => Promise<unknown>;
182 };
183 const query = Drizzle.sql.raw(statement);
184
185 if (target.run) {
186 await target.run(query);
187 return;
188 }
189
190 if (target.execute) {
191 await target.execute(query);
192 return;
193 }
194
195 throw new Error("[FumaDB Drizzle] Database cannot execute raw transaction statements.");
196 }
197
198 function toDrizzle(v: AnyTable): TableType {
199 const out = drizzleTables[v.names.drizzle];
200 if (out) return out;
201
202 throw new Error(
203 `[FumaDB Drizzle] Unknown table name ${v.names.drizzle}, is it included in your Drizzle schema?`
204 );
205 }
206
207 function toDrizzleColumn(v: AnyColumn): ColumnType {
208 const table = toDrizzle(v.table!);
209 const out = table[v.names.drizzle];
210 if (out) return out;
211
212 throw new Error(
213 `[FumaDB Drizzle] Unknown column name ${v.names.drizzle} in ${v.table.names.drizzle}.`
214 );
215 }
216
217 // Drizzle Queries doesn't support renaming fields with `mapWith` because https://github.com/drizzle-team/drizzle-orm/issues/1157
218 // we need to map the result on JS instead of relying on Drizzle
219 function buildQueryConfig(
220 table: AnyTable,
221 options: SimplifyFindOptions<FindManyOptions>
222 ) {
223 const columns: Record<string, boolean> = {};
224 const select = options.select;
225
226 if (select === true) {

Callers 2

createORMFunction · 0.90
transactionFunction · 0.85

Calls 2

parseDrizzleFunction · 0.90
toORMFunction · 0.90

Tested by

no test coverage detected