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

Function create

packages/core/fumadb/src/adapters/kysely/query.ts:396–439  ·  view source on GitHub ↗
(table, values)

Source from the content-addressed store, hash-verified

394 return count;
395 },
396 async create(table, values) {
397 const rawTable = table;
398 const insertValues = encodeValues(values, rawTable, true);
399 const insert = kysely.insertInto(rawTable.names.sql).values(insertValues);
400
401 if (provider === "mssql") {
402 return decodeResult(
403 await insert
404 .output(
405 mapSelect(true, rawTable, { tableName: "inserted" }) as any[]
406 )
407 .executeTakeFirstOrThrow(),
408 rawTable
409 );
410 }
411
412 if (provider === "postgresql" || provider === "sqlite") {
413 return decodeResult(
414 await insert
415 .returning(mapSelect(true, rawTable))
416 .executeTakeFirstOrThrow(),
417 rawTable
418 );
419 }
420
421 const idColumn = rawTable.getIdColumn();
422 const idValue = insertValues[idColumn.names.sql];
423
424 if (idValue == null)
425 throw new Error(
426 "cannot find value of id column, which is required for `create()`."
427 );
428
429 await insert.execute();
430 return decodeResult(
431 await kysely
432 .selectFrom(rawTable.names.sql)
433 .select(mapSelect(true, rawTable))
434 .where(idColumn.names.sql, "=", idValue)
435 .limit(1)
436 .executeTakeFirstOrThrow(),
437 rawTable
438 );
439 },
440 async findFirst(table, v) {
441 const records = await this.findMany(table, {
442 ...v,

Callers

nothing calls this directly

Calls 7

encodeValuesFunction · 0.85
decodeResultFunction · 0.85
valuesMethod · 0.80
limitMethod · 0.80
mapSelectFunction · 0.70
outputMethod · 0.65
executeMethod · 0.65

Tested by

no test coverage detected