(table, v)
| 140 | return (await this.findMany(table, { ...v, limit: 1 }))[0] ?? null; |
| 141 | }, |
| 142 | async findMany(table, v) { |
| 143 | if (v.join?.length) throw new Error("[FumaDB Memory] Joins are not supported."); |
| 144 | let rows = tableRows(db, table).filter((row) => matchesCondition(row, v.where)); |
| 145 | |
| 146 | for (const [column, direction] of [...(v.orderBy ?? [])].reverse()) { |
| 147 | rows = [...rows].sort((a, b) => { |
| 148 | const left = comparable(columnValue(a, column)); |
| 149 | const right = comparable(columnValue(b, column)); |
| 150 | if (left == null && right == null) return 0; |
| 151 | if (left == null) return direction === "asc" ? -1 : 1; |
| 152 | if (right == null) return direction === "asc" ? 1 : -1; |
| 153 | if (left < right) return direction === "asc" ? -1 : 1; |
| 154 | if (left > right) return direction === "asc" ? 1 : -1; |
| 155 | return 0; |
| 156 | }); |
| 157 | } |
| 158 | |
| 159 | const offset = v.offset ?? 0; |
| 160 | const limited = rows.slice(offset, v.limit === undefined ? undefined : offset + v.limit); |
| 161 | return limited.map((row) => selectRow(table, row, v.select)); |
| 162 | }, |
| 163 | async updateMany(table, v) { |
| 164 | for (const row of tableRows(db, table)) { |
| 165 | if (!matchesCondition(row, v.where)) continue; |
nothing calls this directly
no test coverage detected