scan. glob to regex (#14063)

* scan. glob to regex

* lint
This commit is contained in:
Barış Uşaklı
2026-03-05 16:01:03 -05:00
committed by GitHub
parent 5d1a8a11fd
commit 7d50baecf0
6 changed files with 44 additions and 30 deletions

View File

@@ -2,6 +2,7 @@
module.exports = function (module) {
const helpers = require('./helpers');
const dbHelpers = require('../helpers');
module.flushdb = async function () {
await module.pool.query(`DROP SCHEMA "public" CASCADE`);
@@ -84,20 +85,14 @@ module.exports = function (module) {
};
module.scan = async function (params) {
let { match } = params;
if (match.startsWith('*')) {
match = `%${match.substring(1)}`;
}
if (match.endsWith('*')) {
match = `${match.substring(0, match.length - 1)}%`;
}
const regex = dbHelpers.globToRegex(params.match);
const res = await module.pool.query({
text: `
SELECT o."_key"
FROM "legacy_object_live" o
WHERE o."_key" LIKE $1`,
values: [match],
WHERE o."_key" ~ $1`,
values: [regex],
});
return res.rows.map(r => r._key);