Skip to content

Commit 099bc97

Browse files
imports tiny fix.
1 parent 8f4129b commit 099bc97

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

src/Modules.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as sqlite3Module from 'sqlite3';
2+
import * as pgModule from 'pg';
3+
4+
/** @type {import('pg')} */
5+
// @ts-ignore
6+
export const pg = pgModule.default || pgModule;
7+
8+
/** @type {import('sqlite3')} */
9+
// @ts-ignore
10+
export const sqlite3 = sqlite3Module.default || sqlite3Module;

src/TinySQL.mjs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import { open } from 'sqlite';
2-
import * as sqlite3 from 'sqlite3';
3-
import { Pool } from 'pg';
42
import { EventEmitter } from 'events';
53
import { isJsonObject } from 'tiny-essentials';
64

5+
import { pg, sqlite3 } from './Modules.mjs';
76
import PuddySqlQuery from './TinySqlQuery.mjs';
87

9-
const { Database } = sqlite3;
10-
118
/** @typedef {import('pg').Pool} PgPool */
129
/** @typedef {import('sqlite').Database} SqliteDb */
1310

@@ -602,7 +599,7 @@ class PuddySqlInstance {
602599
/** @type {SqliteDb} */
603600
this.#db = await open({
604601
filename: filePath,
605-
driver: Database,
602+
driver: sqlite3.Database,
606603
});
607604

608605
// Set SQL methods (all, get, run)
@@ -626,7 +623,8 @@ class PuddySqlInstance {
626623
* @throws {Error} If a SQL engine has already been set for this instance.
627624
*/
628625
setSqlite3(db) {
629-
if (!(db instanceof Database)) throw new Error('Invalid type for db. Expected a Sqlite3.');
626+
if (!(db instanceof sqlite3.Database))
627+
throw new Error('Invalid type for db. Expected a Sqlite3.');
630628
if (!this.#sqlEngine) {
631629
this.#sqlEngine = 'sqlite3';
632630

@@ -767,7 +765,7 @@ class PuddySqlInstance {
767765
async initPostgre(config) {
768766
if (!this.#sqlEngine) {
769767
/** @type {PgPool} */
770-
this.#db = new Pool(config);
768+
this.#db = new pg.Pool(config);
771769

772770
// Set up the SQL methods (all, get, run)
773771
this.setPostgre(this.#db);
@@ -792,7 +790,7 @@ class PuddySqlInstance {
792790
* @throws {Error} If a SQL engine is already set for this instance.
793791
*/
794792
setPostgre(db) {
795-
if (!(db instanceof Pool)) throw new Error('Invalid type for db. Expected a PostgreSQL.');
793+
if (!(db instanceof pg.Pool)) throw new Error('Invalid type for db. Expected a PostgreSQL.');
796794
if (!this.#sqlEngine) {
797795
this.#sqlEngine = 'postgre';
798796

src/TinySqlQuery.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import * as pg from 'pg';
21
import { isJsonObject } from 'tiny-essentials';
2+
import { pg } from './Modules.mjs';
3+
34
import PuddySqlInstance from './TinySQL.mjs';
45
import PuddySqlTags from './TinySqlTags.mjs';
56

6-
const { Client } = pg;
7-
const clientBase = new Client();
7+
const clientBase = new pg.Client();
88

99
/**
1010
* Tag group definition used to build dynamic SQL clauses for tag filtering.

0 commit comments

Comments
 (0)