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

Function create

packages/core/fumadb/src/adapters/drizzle/query.ts:324–353  ·  view source on GitHub ↗
(table, values)

Source from the content-addressed store, hash-verified

322 },
323
324 async create(table, values) {
325 const idField = table.getIdColumn().names.drizzle;
326 const drizzleTable = toDrizzle(table);
327 values = mapValues(values, table);
328
329 const returning: Record<string, ColumnType> = {};
330 for (const column of Object.values(table.columns)) {
331 returning[column.ormName] = drizzleTable[column.names.drizzle];
332 }
333
334 if (provider === "sqlite" || provider === "postgresql") {
335 const result = await (db as unknown as P_DBType)
336 .insert(drizzleTable as unknown as P_TableType)
337 .values(values)
338 .returning(returning as unknown as Record<string, P_ColumnType>);
339 return result[0];
340 }
341
342 const obj = (
343 await db.insert(drizzleTable).values(values).$returningId()
344 )[0] as Record<string, unknown>;
345
346 return (
347 await db
348 .select(returning)
349 .from(drizzleTable)
350 .where(Drizzle.eq(drizzleTable[idField], obj[idField]))
351 .limit(1)
352 )[0];
353 },
354
355 async createMany(table, values) {
356 const idField = table.getIdColumn().names.drizzle;

Callers

nothing calls this directly

Calls 4

toDrizzleFunction · 0.85
valuesMethod · 0.80
limitMethod · 0.80
mapValuesFunction · 0.70

Tested by

no test coverage detected