Skip to content

Commit 93100b0

Browse files
TinySql --> imports fix.
1 parent 9c6c01a commit 93100b0

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/TinySQL.mjs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { open } from 'sqlite';
22
import * as sqlite3 from 'sqlite3';
3-
import * as pg from 'pg';
3+
import { Pool } from 'pg';
44
import { EventEmitter } from 'events';
55
import { isJsonObject } from 'tiny-essentials';
66

77
import PuddySqlQuery from './TinySqlQuery.mjs';
88

99
const { Database } = sqlite3;
10-
const { Client } = pg;
1110

1211
/** @typedef {import('pg').Pool} PgPool */
1312
/** @typedef {import('sqlite').Database} SqliteDb */
@@ -544,7 +543,7 @@ class PuddySqlInstance {
544543
/**
545544
* Returns the raw database instance currently in use.
546545
*
547-
* This gives direct access to the internal database connection (PostgreSQL `Client` or SQLite3 `Database`),
546+
* This gives direct access to the internal database connection (PostgreSQL `Pool` or SQLite3 `Database`),
548547
* which can be useful for advanced queries or database-specific operations not covered by this wrapper.
549548
*
550549
* @returns {SqliteDb|PgPool} The internal database instance, or `null` if not initialized.
@@ -756,19 +755,19 @@ class PuddySqlInstance {
756755
/**
757756
* Initializes a PostgreSQL client and sets up the SQL engine for this instance.
758757
*
759-
* This method creates a new PostgreSQL `Client` using the given configuration,
758+
* This method creates a new PostgreSQL `Pool` using the given configuration,
760759
* connects to the database, and assigns the SQL engine behavior using `setPostgre()`.
761760
* It also attaches a `SIGINT` listener to gracefully close the database connection
762761
* when the process is terminated.
763762
*
764763
* @param {Object} config - PostgreSQL client configuration object.
765-
* Must be compatible with the `pg` Client constructor.
764+
* Must be compatible with the `pg` Pool constructor.
766765
* @throws {Error} If a SQL engine is already initialized for this instance.
767766
*/
768767
async initPostgre(config) {
769768
if (!this.#sqlEngine) {
770769
/** @type {PgPool} */
771-
this.#db = new Client(config);
770+
this.#db = new Pool(config);
772771

773772
// Set up the SQL methods (all, get, run)
774773
this.setPostgre(this.#db);
@@ -793,7 +792,7 @@ class PuddySqlInstance {
793792
* @throws {Error} If a SQL engine is already set for this instance.
794793
*/
795794
setPostgre(db) {
796-
if (!(db instanceof pg.Pool)) throw new Error('Invalid type for db. Expected a PostgreSQL.');
795+
if (!(db instanceof Pool)) throw new Error('Invalid type for db. Expected a PostgreSQL.');
797796
if (!this.#sqlEngine) {
798797
this.#sqlEngine = 'postgre';
799798

src/TinySqlQuery.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import * as pg from 'pg';
1+
import { Client } from 'pg';
22
import { isJsonObject } from 'tiny-essentials';
33
import PuddySqlInstance from './TinySQL.mjs';
44
import PuddySqlTags from './TinySqlTags.mjs';
55

6-
const { Client } = pg;
76
const clientBase = new Client();
87

98
/**

0 commit comments

Comments
 (0)