| 174 | } |
| 175 | |
| 176 | export 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 | |
| 206 | function rowKeys(row: Record<string, unknown>, keys: string[]): string[] { |
| 207 | let output: string[] = [] |