MCPcopy
hub / github.com/eveningkid/denodb / update

Method update

lib/model.ts:645–673  ·  view source on GitHub ↗

Update one or multiple records. Also update `updated_at` if `timestamps` is `true`. * * await Flight.where("departure", "Dublin").update("departure", "Tokyo"); * * await Flight.where("departure", "Dublin").update({ destination: "Tokyo" });

(fieldOrFields: string | Values, fieldValue?: FieldValue)

Source from the content-addressed store, hash-verified

643 * await Flight.where("departure", "Dublin").update({ destination: "Tokyo" });
644 */
645 static update(fieldOrFields: string | Values, fieldValue?: FieldValue) {
646 let fieldsToUpdate: Values = {};
647
648 if (this.timestamps) {
649 fieldsToUpdate[
650 this.formatFieldToDatabase("updated_at") as string
651 ] = new Date();
652 }
653
654 if (typeof fieldOrFields === "string") {
655 fieldsToUpdate[
656 this.formatFieldToDatabase(fieldOrFields) as string
657 ] = fieldValue!;
658 } else {
659 fieldsToUpdate = {
660 ...fieldsToUpdate,
661 ...(this.formatFieldToDatabase(fieldOrFields) as {
662 [fieldName: string]: any;
663 }),
664 };
665 }
666
667 return this._runQuery(
668 this._currentQuery
669 .table(this.table)
670 .update(fieldsToUpdate)
671 .toDescription(),
672 ) as Promise<Model | Model[]>;
673 }
674
675 /** Delete a record by a primary key value.
676 *

Callers 4

translateToQueryMethod · 0.45
update.test.tsFile · 0.45
update.test.tsFile · 0.45
response.test.tsFile · 0.45

Calls 7

formatFieldToDatabaseMethod · 0.95
_runQueryMethod · 0.95
_getCurrentPrimaryKeyMethod · 0.95
toDescriptionMethod · 0.80
tableMethod · 0.80
getComputedPrimaryKeyMethod · 0.80
whereMethod · 0.45

Tested by

no test coverage detected