MCPcopy
hub / github.com/remix-run/remix / buildPrimaryKeyPredicate

Function buildPrimaryKeyPredicate

packages/data-table/src/lib/database/helpers.ts:176–204  ·  view source on GitHub ↗
(
  table: table,
  keyObjects: Record<string, unknown>[],
)

Source from the content-addressed store, hash-verified

174}
175
176export function buildPrimaryKeyPredicate<table extends AnyTable>(
177 table: table,
178 keyObjects: Record<string, unknown>[],
179): Predicate<TableColumnName<table>> | undefined {
180 let primaryKey = getTablePrimaryKey(table)
181
182 if (keyObjects.length === 0) {
183 return undefined
184 }
185
186 if (primaryKey.length === 1) {
187 let key = primaryKey[0] as TableColumnName<table>
188 return inList(
189 key,
190 keyObjects.map((objectValue) => objectValue[key]),
191 )
192 }
193
194 let predicates = keyObjects.map((objectValue) => {
195 let comparisons = primaryKey.map((key) => {
196 let typedKey = key as TableColumnName<table>
197 return eq(typedKey, objectValue[typedKey])
198 })
199
200 return and(...comparisons)
201 })
202
203 return or(...predicates)
204}
205
206function rowKeys(row: Record<string, unknown>, keys: string[]): string[] {
207 let output: string[] = []

Callers 2

executeUpdateFunction · 0.90
executeDeleteFunction · 0.90

Calls 6

getTablePrimaryKeyFunction · 0.90
inListFunction · 0.90
eqFunction · 0.90
andFunction · 0.90
orFunction · 0.90
mapMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…