Skip to content

Commit c4966e5

Browse files
PuddySql --> pg and sqlite3 added.
1 parent 099bc97 commit c4966e5

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/TinySqlQuery.mjs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { isJsonObject } from 'tiny-essentials';
22
import { pg } from './Modules.mjs';
3-
43
import PuddySqlInstance from './TinySQL.mjs';
54
import PuddySqlTags from './TinySqlTags.mjs';
65

7-
const clientBase = new pg.Client();
8-
96
/**
107
* Tag group definition used to build dynamic SQL clauses for tag filtering.
118
*
@@ -432,7 +429,7 @@ class PuddySqlQuery {
432429
* - `weight` (number): numeric weight applied when condition matches (default: 1)
433430
* - If `columns` is omitted, the `value` is treated as a raw SQL condition inserted directly into the CASE.
434431
*
435-
* Escaping of all values is handled by `Client.escapeLiteral()` for SQL safety (PostgreSQL).
432+
* Escaping of all values is handled by `pg.escapeLiteral()` for SQL safety (PostgreSQL).
436433
*
437434
* @param {SelectQuery} input - Select clause definition.
438435
* @returns {string} - A valid SQL SELECT clause string.
@@ -524,7 +521,7 @@ class PuddySqlQuery {
524521
if (opValue === 'IN') {
525522
const conditions = columns.map((col) => {
526523
if (Array.isArray(value)) {
527-
const inList = value.map((v) => clientBase.escapeLiteral(v)).join(', ');
524+
const inList = value.map((v) => pg.escapeLiteral(v)).join(', ');
528525
return `${col} IN (${inList})`;
529526
} else {
530527
console.warn(`IN operator expected array, got`, value);
@@ -533,7 +530,7 @@ class PuddySqlQuery {
533530
});
534531
cases.push(`WHEN ${conditions.join(' OR ')} THEN ${weight}`);
535532
} else {
536-
const safeVal = clientBase.escapeLiteral(
533+
const safeVal = pg.escapeLiteral(
537534
['LIKE', 'ILIKE'].includes(opValue) ? `%${value}%` : value,
538535
);
539536
const conditions = columns.map((col) => `${col} ${operator} ${safeVal}`);

src/index.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { pg, sqlite3 } from './Modules.mjs';
12
import PuddySqlEvents from './Events.mjs';
23
import PuddySqlInstance from './TinySQL.mjs';
34
import PuddySqlQuery from './TinySqlQuery.mjs';
@@ -8,6 +9,8 @@ class PuddySql {
89
static Query = PuddySqlQuery;
910
static Tags = PuddySqlTags;
1011
static Events = PuddySqlEvents;
12+
static pg = pg;
13+
static sqlite3 = sqlite3;
1114

1215
/**
1316
* This constructor is intentionally blocked.

0 commit comments

Comments
 (0)