(builder: any, tableFields: string[], criteria?: string[])
| 149 | } |
| 150 | |
| 151 | private applyHexCriteria(builder: any, tableFields: string[], criteria?: string[]): void { |
| 152 | if (typeof criteria === 'undefined') { |
| 153 | return |
| 154 | } |
| 155 | |
| 156 | if (!criteria.length) { |
| 157 | builder.whereRaw('1 = 0') |
| 158 | return |
| 159 | } |
| 160 | |
| 161 | const groups = this.groupHexCriteria(criteria) |
| 162 | |
| 163 | tableFields.forEach((tableField) => { |
| 164 | if (groups.exact.length) { |
| 165 | builder.orWhereIn(tableField, groups.exact.map(toBuffer)) |
| 166 | } |
| 167 | |
| 168 | groups.even.forEach((prefix) => { |
| 169 | builder.orWhereRaw(`substring("${tableField}" from 1 for ?) = ?`, [prefix.length >> 1, toBuffer(prefix)]) |
| 170 | }) |
| 171 | |
| 172 | groups.odd.forEach((prefix) => { |
| 173 | builder.orWhereRaw(`substring("${tableField}" from 1 for ?) BETWEEN ? AND ?`, [ |
| 174 | (prefix.length >> 1) + 1, |
| 175 | `\\x${prefix}0`, |
| 176 | `\\x${prefix}f`, |
| 177 | ]) |
| 178 | }) |
| 179 | }) |
| 180 | } |
| 181 | |
| 182 | private groupHexCriteria(criteria: string[]): HexCriterionGroups { |
| 183 | return criteria.reduce<HexCriterionGroups>( |
no test coverage detected