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

Method _computeModelFieldMatchings

lib/database.ts:263–301  ·  view source on GitHub ↗

Compute field matchings tables for model usage.

(
    table: string,
    fields: ModelFields,
    withTimestamps: boolean,
  )

Source from the content-addressed store, hash-verified

261
262 /** Compute field matchings tables for model usage. */
263 _computeModelFieldMatchings(
264 table: string,
265 fields: ModelFields,
266 withTimestamps: boolean,
267 ): {
268 toClient: FieldMatchingTable;
269 toDatabase: FieldMatchingTable;
270 } {
271 const modelFields = { ...fields };
272 if (withTimestamps) {
273 modelFields.updatedAt = "";
274 modelFields.createdAt = "";
275 }
276
277 const toDatabase: FieldMatchingTable = Object.entries(modelFields).reduce(
278 (prev: any, [clientFieldName, fieldType]) => {
279 const databaseFieldName = typeof fieldType !== "string" && fieldType.as
280 ? fieldType.as
281 : (this._translator.formatFieldNameToDatabase(
282 clientFieldName,
283 ) as string);
284
285 prev[clientFieldName] = databaseFieldName;
286 prev[`${table}.${clientFieldName}`] = `${table}.${databaseFieldName}`;
287 return prev;
288 },
289 {},
290 );
291
292 const toClient: FieldMatchingTable = Object.entries(toDatabase).reduce(
293 (prev, [clientFieldName, databaseFieldName]) => ({
294 ...prev,
295 [databaseFieldName]: clientFieldName,
296 }),
297 {},
298 );
299
300 return { toDatabase, toClient };
301 }
302
303 /** Close the current database connection. */
304 close() {

Callers 1

_linkMethod · 0.80

Calls 1

Tested by

no test coverage detected