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

Function create

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

Source from the content-addressed store, hash-verified

550 },
551
552 async create(table, values) {
553 const idField = table.getIdColumn().names.drizzle;
554 const drizzleTable = toDrizzle(table);
555 values = mapValues(values, table);
556
557 const returning: Record<string, ColumnType> = {};
558 for (const column of Object.values(table.columns)) {
559 returning[column.ormName] = drizzleTable[column.names.drizzle];
560 }
561
562 if (provider === "sqlite" || provider === "postgresql") {
563 const result = await (db as unknown as P_DBType)
564 .insert(drizzleTable as unknown as P_TableType)
565 .values(values)
566 .returning(returning as unknown as Record<string, P_ColumnType>);
567 return result[0];
568 }
569
570 const obj = (
571 await db.insert(drizzleTable).values(values).$returningId()
572 )[0] as Record<string, unknown>;
573
574 return (
575 await db
576 .select(returning)
577 .from(drizzleTable)
578 .where(Drizzle.eq(drizzleTable[idField], obj[idField]))
579 .limit(1)
580 )[0];
581 },
582
583 async createMany(table, values) {
584 if (values.length === 0) return [];

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