Skip to main content

@rtorcato/db-common / mapRow

Function: mapRow()

mapRow<T>(row, spec): T

Defined in: map-rows.ts:18

Map a driver row ({ snake_col: value }) into a typed object, renaming the columns named in spec and coercing where a function is given. Columns not in spec are dropped — the spec is the allowlist of fields you expose.

mapRow({ user_id: 1, is_active: 1 }, { user_id: 'id', is_active: ['active', Boolean] }) // → { id: 1, active: true }

Type Parameters​

T​

T

Parameters​

row​

Record<string, unknown>

spec​

RowSpec<T>

Returns​

T