MCPcopy Create free account
hub / github.com/cameri/nostream / applyHexCriteria

Method applyHexCriteria

src/repositories/event-repository.ts:151–180  ·  view source on GitHub ↗
(builder: any, tableFields: string[], criteria?: string[])

Source from the content-addressed store, hash-verified

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>(

Callers 1

Calls 2

groupHexCriteriaMethod · 0.95
toBufferFunction · 0.90

Tested by

no test coverage detected