@hawiah/postgres 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +23 -0
- package/dist/drivers/PostgreSQLDriver.d.ts +168 -0
- package/dist/drivers/PostgreSQLDriver.d.ts.map +1 -0
- package/dist/drivers/PostgreSQLDriver.js +294 -0
- package/dist/drivers/PostgreSQLDriver.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/IDriver.d.ts +69 -0
- package/dist/interfaces/IDriver.d.ts.map +1 -0
- package/dist/interfaces/IDriver.js +2 -0
- package/dist/interfaces/IDriver.js.map +1 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 HAWIAH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @hawiah/postgres [](https://npmjs.com/package/@hawiah/postgres)
|
|
2
|
+
|
|
3
|
+
PostgreSQL driver with schema-less JSONB storage for Node.js applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @hawiah/postgres
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- Schema-less data storage using PostgreSQL JSONB
|
|
14
|
+
- Connection pooling with node-postgres (pg)
|
|
15
|
+
- Support for cloud providers (Neon, Supabase, etc.)
|
|
16
|
+
- Transaction support
|
|
17
|
+
- Unified IDriver interface
|
|
18
|
+
- Automatic table creation and indexing
|
|
19
|
+
- Raw SQL query execution support
|
|
20
|
+
|
|
21
|
+
## License
|
|
22
|
+
|
|
23
|
+
MIT
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { Pool, PoolClient, PoolConfig } from 'pg';
|
|
2
|
+
import { IDriver, Query, Data } from '../interfaces/IDriver';
|
|
3
|
+
/**
|
|
4
|
+
* PostgreSQL driver configuration options
|
|
5
|
+
*/
|
|
6
|
+
export interface PostgreSQLDriverOptions {
|
|
7
|
+
/**
|
|
8
|
+
* PostgreSQL connection string (recommended)
|
|
9
|
+
* Example: 'postgresql://user:password@host:port/database'
|
|
10
|
+
*/
|
|
11
|
+
connectionString?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Or individual connection parameters
|
|
14
|
+
*/
|
|
15
|
+
host?: string;
|
|
16
|
+
port?: number;
|
|
17
|
+
user?: string;
|
|
18
|
+
password?: string;
|
|
19
|
+
database?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Table name to use
|
|
22
|
+
*/
|
|
23
|
+
tableName: string;
|
|
24
|
+
/**
|
|
25
|
+
* SSL configuration (required for cloud providers like Neon, Supabase)
|
|
26
|
+
*/
|
|
27
|
+
ssl?: boolean | object;
|
|
28
|
+
/**
|
|
29
|
+
* Connection pool size (default: 10)
|
|
30
|
+
*/
|
|
31
|
+
max?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Additional PostgreSQL pool options
|
|
34
|
+
*/
|
|
35
|
+
poolOptions?: PoolConfig;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Driver implementation for PostgreSQL using node-postgres.
|
|
39
|
+
* Provides a schema-less interface to PostgreSQL tables with JSONB storage.
|
|
40
|
+
*/
|
|
41
|
+
export declare class PostgreSQLDriver implements IDriver {
|
|
42
|
+
private pool;
|
|
43
|
+
private tableName;
|
|
44
|
+
private config;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new instance of PostgreSQLDriver
|
|
47
|
+
* @param options - PostgreSQL driver configuration options
|
|
48
|
+
*/
|
|
49
|
+
constructor(options: PostgreSQLDriverOptions);
|
|
50
|
+
/**
|
|
51
|
+
* Connects to the PostgreSQL database.
|
|
52
|
+
* Creates the table if it doesn't exist.
|
|
53
|
+
*/
|
|
54
|
+
connect(): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Disconnects from the PostgreSQL database.
|
|
57
|
+
*/
|
|
58
|
+
disconnect(): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Inserts a new record into the database.
|
|
61
|
+
* @param data - The data to insert
|
|
62
|
+
* @returns The inserted record with ID
|
|
63
|
+
*/
|
|
64
|
+
set(data: Data): Promise<Data>;
|
|
65
|
+
/**
|
|
66
|
+
* Retrieves records matching the query.
|
|
67
|
+
* @param query - The query criteria
|
|
68
|
+
* @returns Array of matching records
|
|
69
|
+
*/
|
|
70
|
+
get(query: Query): Promise<Data[]>;
|
|
71
|
+
/**
|
|
72
|
+
* Retrieves a single record matching the query.
|
|
73
|
+
* @param query - The query criteria
|
|
74
|
+
* @returns The first matching record or null
|
|
75
|
+
*/
|
|
76
|
+
getOne(query: Query): Promise<Data | null>;
|
|
77
|
+
/**
|
|
78
|
+
* Updates records matching the query.
|
|
79
|
+
* @param query - The query criteria
|
|
80
|
+
* @param data - The data to update
|
|
81
|
+
* @returns The number of updated records
|
|
82
|
+
*/
|
|
83
|
+
update(query: Query, data: Data): Promise<number>;
|
|
84
|
+
/**
|
|
85
|
+
* Deletes records matching the query.
|
|
86
|
+
* @param query - The query criteria
|
|
87
|
+
* @returns The number of deleted records
|
|
88
|
+
*/
|
|
89
|
+
delete(query: Query): Promise<number>;
|
|
90
|
+
/**
|
|
91
|
+
* Checks if any record matches the query.
|
|
92
|
+
* @param query - The query criteria
|
|
93
|
+
* @returns True if a match exists, false otherwise
|
|
94
|
+
*/
|
|
95
|
+
exists(query: Query): Promise<boolean>;
|
|
96
|
+
/**
|
|
97
|
+
* Counts records matching the query.
|
|
98
|
+
* @param query - The query criteria
|
|
99
|
+
* @returns The number of matching records
|
|
100
|
+
*/
|
|
101
|
+
count(query: Query): Promise<number>;
|
|
102
|
+
/**
|
|
103
|
+
* Ensures the database is connected before executing operations.
|
|
104
|
+
* @throws Error if database is not connected
|
|
105
|
+
* @private
|
|
106
|
+
*/
|
|
107
|
+
private ensureConnected;
|
|
108
|
+
/**
|
|
109
|
+
* Generates a unique ID for records.
|
|
110
|
+
* @returns A unique string ID
|
|
111
|
+
* @private
|
|
112
|
+
*/
|
|
113
|
+
private generateId;
|
|
114
|
+
/**
|
|
115
|
+
* Checks if a record matches the query criteria.
|
|
116
|
+
* @param record - The record to check
|
|
117
|
+
* @param query - The query criteria
|
|
118
|
+
* @returns True if the record matches
|
|
119
|
+
* @private
|
|
120
|
+
*/
|
|
121
|
+
private matchesQuery;
|
|
122
|
+
/**
|
|
123
|
+
* Gets the PostgreSQL connection pool.
|
|
124
|
+
* @returns The PostgreSQL connection pool
|
|
125
|
+
*/
|
|
126
|
+
getPool(): Pool | null;
|
|
127
|
+
/**
|
|
128
|
+
* Executes a raw SQL query.
|
|
129
|
+
* WARNING: Use with caution. This bypasses the abstraction layer.
|
|
130
|
+
* @param sql - The SQL query to execute
|
|
131
|
+
* @param params - Optional parameters for the query
|
|
132
|
+
* @returns Query results
|
|
133
|
+
*/
|
|
134
|
+
executeRaw(sql: string, params?: any[]): Promise<any>;
|
|
135
|
+
/**
|
|
136
|
+
* Clears all data from the table.
|
|
137
|
+
*/
|
|
138
|
+
clear(): Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* Drops the entire table.
|
|
141
|
+
* WARNING: This will permanently delete all data and indexes.
|
|
142
|
+
*/
|
|
143
|
+
drop(): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Vacuums the table for optimization.
|
|
146
|
+
*/
|
|
147
|
+
vacuum(): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Analyzes the table for query optimization.
|
|
150
|
+
*/
|
|
151
|
+
analyze(): Promise<void>;
|
|
152
|
+
/**
|
|
153
|
+
* Begins a transaction.
|
|
154
|
+
* @returns A client from the pool for transaction use
|
|
155
|
+
*/
|
|
156
|
+
beginTransaction(): Promise<PoolClient>;
|
|
157
|
+
/**
|
|
158
|
+
* Commits a transaction.
|
|
159
|
+
* @param client - The client to commit
|
|
160
|
+
*/
|
|
161
|
+
commit(client: PoolClient): Promise<void>;
|
|
162
|
+
/**
|
|
163
|
+
* Rolls back a transaction.
|
|
164
|
+
* @param client - The client to rollback
|
|
165
|
+
*/
|
|
166
|
+
rollback(client: PoolClient): Promise<void>;
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=PostgreSQLDriver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PostgreSQLDriver.d.ts","sourceRoot":"","sources":["../../src/drivers/PostgreSQLDriver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU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G,OAAO,CAAC,MAAM,CAAC;IAiCvD;;;;OAIG;IACG,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;IAe3C;;;;OAIG;IACG,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC;IAO5C;;;;OAIG;IACG,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;IAa1C;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAMvB;;;;OAIG;IACH,OAAO,CAAC,UAAU;IAIlB;;;;;;OAMG;IACH,OAAO,CAAC,YAAY;IASpB;;;OAGG;IACH,OAAO,IAAI,IAAI,GAAG,IAAI;IAItB;;;;;;OAMG;IACG,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IAM3D;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAK5B;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAK3B;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAK7B;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAK9B;;;OAGG;IACG,gBAAgB,IAAI,OAAO,CAAC,UAAU,CAAC;IAO7C;;;OAGG;IACG,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAK/C;;;OAGG;IACG,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAIpD"}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { Pool } from 'pg';
|
|
2
|
+
/**
|
|
3
|
+
* Driver implementation for PostgreSQL using node-postgres.
|
|
4
|
+
* Provides a schema-less interface to PostgreSQL tables with JSONB storage.
|
|
5
|
+
*/
|
|
6
|
+
export class PostgreSQLDriver {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new instance of PostgreSQLDriver
|
|
9
|
+
* @param options - PostgreSQL driver configuration options
|
|
10
|
+
*/
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.pool = null;
|
|
13
|
+
this.tableName = options.tableName;
|
|
14
|
+
this.config = {
|
|
15
|
+
connectionString: options.connectionString,
|
|
16
|
+
host: options.host,
|
|
17
|
+
port: options.port,
|
|
18
|
+
user: options.user,
|
|
19
|
+
password: options.password,
|
|
20
|
+
database: options.database,
|
|
21
|
+
max: options.max || 10,
|
|
22
|
+
ssl: options.ssl !== undefined ? options.ssl : (options.connectionString?.includes('sslmode=require') ? { rejectUnauthorized: false } : false),
|
|
23
|
+
...options.poolOptions,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Connects to the PostgreSQL database.
|
|
28
|
+
* Creates the table if it doesn't exist.
|
|
29
|
+
*/
|
|
30
|
+
async connect() {
|
|
31
|
+
this.pool = new Pool(this.config);
|
|
32
|
+
const createTableSQL = `
|
|
33
|
+
CREATE TABLE IF NOT EXISTS ${this.tableName} (
|
|
34
|
+
_id VARCHAR(100) PRIMARY KEY,
|
|
35
|
+
_data JSONB NOT NULL,
|
|
36
|
+
_createdAt TIMESTAMP NOT NULL,
|
|
37
|
+
_updatedAt TIMESTAMP NOT NULL
|
|
38
|
+
)
|
|
39
|
+
`;
|
|
40
|
+
await this.pool.query(createTableSQL);
|
|
41
|
+
await this.pool.query(`CREATE INDEX IF NOT EXISTS idx_${this.tableName}_createdAt ON ${this.tableName}(_createdAt)`);
|
|
42
|
+
await this.pool.query(`CREATE INDEX IF NOT EXISTS idx_${this.tableName}_updatedAt ON ${this.tableName}(_updatedAt)`);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Disconnects from the PostgreSQL database.
|
|
46
|
+
*/
|
|
47
|
+
async disconnect() {
|
|
48
|
+
if (this.pool) {
|
|
49
|
+
await this.pool.end();
|
|
50
|
+
this.pool = null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Inserts a new record into the database.
|
|
55
|
+
* @param data - The data to insert
|
|
56
|
+
* @returns The inserted record with ID
|
|
57
|
+
*/
|
|
58
|
+
async set(data) {
|
|
59
|
+
this.ensureConnected();
|
|
60
|
+
const id = this.generateId();
|
|
61
|
+
const now = new Date();
|
|
62
|
+
const record = {
|
|
63
|
+
...data,
|
|
64
|
+
_id: id,
|
|
65
|
+
_createdAt: now.toISOString(),
|
|
66
|
+
_updatedAt: now.toISOString(),
|
|
67
|
+
};
|
|
68
|
+
const sql = `
|
|
69
|
+
INSERT INTO ${this.tableName} (_id, _data, _createdAt, _updatedAt)
|
|
70
|
+
VALUES ($1, $2, $3, $4)
|
|
71
|
+
`;
|
|
72
|
+
await this.pool.query(sql, [
|
|
73
|
+
id,
|
|
74
|
+
JSON.stringify(record),
|
|
75
|
+
now,
|
|
76
|
+
now,
|
|
77
|
+
]);
|
|
78
|
+
return record;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Retrieves records matching the query.
|
|
82
|
+
* @param query - The query criteria
|
|
83
|
+
* @returns Array of matching records
|
|
84
|
+
*/
|
|
85
|
+
async get(query) {
|
|
86
|
+
this.ensureConnected();
|
|
87
|
+
const sql = `SELECT _data FROM ${this.tableName}`;
|
|
88
|
+
const result = await this.pool.query(sql);
|
|
89
|
+
const allRecords = result.rows.map((row) => row._data);
|
|
90
|
+
if (Object.keys(query).length === 0) {
|
|
91
|
+
return allRecords;
|
|
92
|
+
}
|
|
93
|
+
return allRecords.filter((record) => this.matchesQuery(record, query));
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Retrieves a single record matching the query.
|
|
97
|
+
* @param query - The query criteria
|
|
98
|
+
* @returns The first matching record or null
|
|
99
|
+
*/
|
|
100
|
+
async getOne(query) {
|
|
101
|
+
this.ensureConnected();
|
|
102
|
+
if (query._id) {
|
|
103
|
+
const sql = `SELECT _data FROM ${this.tableName} WHERE _id = $1 LIMIT 1`;
|
|
104
|
+
const result = await this.pool.query(sql, [query._id]);
|
|
105
|
+
if (result.rows.length > 0) {
|
|
106
|
+
return result.rows[0]._data;
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
const results = await this.get(query);
|
|
111
|
+
return results.length > 0 ? results[0] : null;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Updates records matching the query.
|
|
115
|
+
* @param query - The query criteria
|
|
116
|
+
* @param data - The data to update
|
|
117
|
+
* @returns The number of updated records
|
|
118
|
+
*/
|
|
119
|
+
async update(query, data) {
|
|
120
|
+
this.ensureConnected();
|
|
121
|
+
const records = await this.get(query);
|
|
122
|
+
let count = 0;
|
|
123
|
+
const sql = `
|
|
124
|
+
UPDATE ${this.tableName}
|
|
125
|
+
SET _data = $1, _updatedAt = $2
|
|
126
|
+
WHERE _id = $3
|
|
127
|
+
`;
|
|
128
|
+
for (const record of records) {
|
|
129
|
+
const updatedRecord = {
|
|
130
|
+
...record,
|
|
131
|
+
...data,
|
|
132
|
+
_updatedAt: new Date().toISOString(),
|
|
133
|
+
};
|
|
134
|
+
updatedRecord._id = record._id;
|
|
135
|
+
updatedRecord._createdAt = record._createdAt;
|
|
136
|
+
await this.pool.query(sql, [
|
|
137
|
+
JSON.stringify(updatedRecord),
|
|
138
|
+
new Date(),
|
|
139
|
+
record._id,
|
|
140
|
+
]);
|
|
141
|
+
count++;
|
|
142
|
+
}
|
|
143
|
+
return count;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Deletes records matching the query.
|
|
147
|
+
* @param query - The query criteria
|
|
148
|
+
* @returns The number of deleted records
|
|
149
|
+
*/
|
|
150
|
+
async delete(query) {
|
|
151
|
+
this.ensureConnected();
|
|
152
|
+
const records = await this.get(query);
|
|
153
|
+
const sql = `DELETE FROM ${this.tableName} WHERE _id = $1`;
|
|
154
|
+
let count = 0;
|
|
155
|
+
for (const record of records) {
|
|
156
|
+
await this.pool.query(sql, [record._id]);
|
|
157
|
+
count++;
|
|
158
|
+
}
|
|
159
|
+
return count;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Checks if any record matches the query.
|
|
163
|
+
* @param query - The query criteria
|
|
164
|
+
* @returns True if a match exists, false otherwise
|
|
165
|
+
*/
|
|
166
|
+
async exists(query) {
|
|
167
|
+
this.ensureConnected();
|
|
168
|
+
const result = await this.getOne(query);
|
|
169
|
+
return result !== null;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Counts records matching the query.
|
|
173
|
+
* @param query - The query criteria
|
|
174
|
+
* @returns The number of matching records
|
|
175
|
+
*/
|
|
176
|
+
async count(query) {
|
|
177
|
+
this.ensureConnected();
|
|
178
|
+
if (Object.keys(query).length === 0) {
|
|
179
|
+
const sql = `SELECT COUNT(*) as count FROM ${this.tableName}`;
|
|
180
|
+
const result = await this.pool.query(sql);
|
|
181
|
+
return parseInt(result.rows[0].count);
|
|
182
|
+
}
|
|
183
|
+
const results = await this.get(query);
|
|
184
|
+
return results.length;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Ensures the database is connected before executing operations.
|
|
188
|
+
* @throws Error if database is not connected
|
|
189
|
+
* @private
|
|
190
|
+
*/
|
|
191
|
+
ensureConnected() {
|
|
192
|
+
if (!this.pool) {
|
|
193
|
+
throw new Error('Database not connected. Call connect() first.');
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Generates a unique ID for records.
|
|
198
|
+
* @returns A unique string ID
|
|
199
|
+
* @private
|
|
200
|
+
*/
|
|
201
|
+
generateId() {
|
|
202
|
+
return `${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Checks if a record matches the query criteria.
|
|
206
|
+
* @param record - The record to check
|
|
207
|
+
* @param query - The query criteria
|
|
208
|
+
* @returns True if the record matches
|
|
209
|
+
* @private
|
|
210
|
+
*/
|
|
211
|
+
matchesQuery(record, query) {
|
|
212
|
+
for (const [key, value] of Object.entries(query)) {
|
|
213
|
+
if (record[key] !== value) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Gets the PostgreSQL connection pool.
|
|
221
|
+
* @returns The PostgreSQL connection pool
|
|
222
|
+
*/
|
|
223
|
+
getPool() {
|
|
224
|
+
return this.pool;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Executes a raw SQL query.
|
|
228
|
+
* WARNING: Use with caution. This bypasses the abstraction layer.
|
|
229
|
+
* @param sql - The SQL query to execute
|
|
230
|
+
* @param params - Optional parameters for the query
|
|
231
|
+
* @returns Query results
|
|
232
|
+
*/
|
|
233
|
+
async executeRaw(sql, params) {
|
|
234
|
+
this.ensureConnected();
|
|
235
|
+
const result = await this.pool.query(sql, params);
|
|
236
|
+
return result.rows;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Clears all data from the table.
|
|
240
|
+
*/
|
|
241
|
+
async clear() {
|
|
242
|
+
this.ensureConnected();
|
|
243
|
+
await this.pool.query(`DELETE FROM ${this.tableName}`);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Drops the entire table.
|
|
247
|
+
* WARNING: This will permanently delete all data and indexes.
|
|
248
|
+
*/
|
|
249
|
+
async drop() {
|
|
250
|
+
this.ensureConnected();
|
|
251
|
+
await this.pool.query(`DROP TABLE IF EXISTS ${this.tableName}`);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Vacuums the table for optimization.
|
|
255
|
+
*/
|
|
256
|
+
async vacuum() {
|
|
257
|
+
this.ensureConnected();
|
|
258
|
+
await this.pool.query(`VACUUM ${this.tableName}`);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Analyzes the table for query optimization.
|
|
262
|
+
*/
|
|
263
|
+
async analyze() {
|
|
264
|
+
this.ensureConnected();
|
|
265
|
+
await this.pool.query(`ANALYZE ${this.tableName}`);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Begins a transaction.
|
|
269
|
+
* @returns A client from the pool for transaction use
|
|
270
|
+
*/
|
|
271
|
+
async beginTransaction() {
|
|
272
|
+
this.ensureConnected();
|
|
273
|
+
const client = await this.pool.connect();
|
|
274
|
+
await client.query('BEGIN');
|
|
275
|
+
return client;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Commits a transaction.
|
|
279
|
+
* @param client - The client to commit
|
|
280
|
+
*/
|
|
281
|
+
async commit(client) {
|
|
282
|
+
await client.query('COMMIT');
|
|
283
|
+
client.release();
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Rolls back a transaction.
|
|
287
|
+
* @param client - The client to rollback
|
|
288
|
+
*/
|
|
289
|
+
async rollback(client) {
|
|
290
|
+
await client.query('ROLLBACK');
|
|
291
|
+
client.release();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
//# sourceMappingURL=PostgreSQLDriver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PostgreSQLDriver.js","sourceRoot":"","sources":["../../src/drivers/PostgreSQLDriver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAA0B,MAAM,IAAI,CAAC;AA2ClD;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IAKzB;;;OAGG;IACH,YAAY,OAAgC;QARpC,SAAI,GAAgB,IAAI,CAAC;QAS7B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QAEnC,IAAI,CAAC,MAAM,GAAG;YACV,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;YAC1C,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,QAAQ,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AAE,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAA2B,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query interface for filtering data
|
|
3
|
+
*/
|
|
4
|
+
export interface Query {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Data interface for storing information
|
|
9
|
+
*/
|
|
10
|
+
export interface Data {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Driver interface that all database drivers must implement
|
|
15
|
+
*/
|
|
16
|
+
export interface IDriver {
|
|
17
|
+
/**
|
|
18
|
+
* Connect to the database
|
|
19
|
+
*/
|
|
20
|
+
connect(): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Disconnect from the database
|
|
23
|
+
*/
|
|
24
|
+
disconnect(): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Set/Insert data into the database
|
|
27
|
+
* @param data - The data to store
|
|
28
|
+
* @returns The stored data with any additional fields (like auto-generated IDs)
|
|
29
|
+
*/
|
|
30
|
+
set(data: Data): Promise<Data>;
|
|
31
|
+
/**
|
|
32
|
+
* Get data from the database based on query
|
|
33
|
+
* @param query - The query to filter data
|
|
34
|
+
* @returns Array of matching records
|
|
35
|
+
*/
|
|
36
|
+
get(query: Query): Promise<Data[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Update data in the database
|
|
39
|
+
* @param query - The query to find records to update
|
|
40
|
+
* @param data - The new data to set
|
|
41
|
+
* @returns Number of updated records
|
|
42
|
+
*/
|
|
43
|
+
update(query: Query, data: Data): Promise<number>;
|
|
44
|
+
/**
|
|
45
|
+
* Delete data from the database
|
|
46
|
+
* @param query - The query to find records to delete
|
|
47
|
+
* @returns Number of deleted records
|
|
48
|
+
*/
|
|
49
|
+
delete(query: Query): Promise<number>;
|
|
50
|
+
/**
|
|
51
|
+
* Get a single record from the database
|
|
52
|
+
* @param query - The query to filter data
|
|
53
|
+
* @returns A single matching record or null
|
|
54
|
+
*/
|
|
55
|
+
getOne(query: Query): Promise<Data | null>;
|
|
56
|
+
/**
|
|
57
|
+
* Check if a record exists
|
|
58
|
+
* @param query - The query to check
|
|
59
|
+
* @returns True if exists, false otherwise
|
|
60
|
+
*/
|
|
61
|
+
exists(query: Query): Promise<boolean>;
|
|
62
|
+
/**
|
|
63
|
+
* Count records matching the query
|
|
64
|
+
* @param query - The query to filter data
|
|
65
|
+
* @returns Number of matching records
|
|
66
|
+
*/
|
|
67
|
+
count(query: Query): Promise<number>;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=IDriver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDriver.d.ts","sourceRoot":"","sources":["../../src/interfaces/IDriver.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,IAAI;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB;;OAEG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB;;OAEG;IACH,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5B;;;;OAIG;IACH,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE/B;;;;OAIG;IACH,GAAG,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IAEnC;;;;;OAKG;IACH,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAElD;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEtC;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAE3C;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEvC;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDriver.js","sourceRoot":"","sources":["../../src/interfaces/IDriver.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hawiah/postgres",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "PostgreSQL driver with schema-less JSONB storage - lightweight and fast data persistence for Node.js",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"dev": "tsc --watch",
|
|
11
|
+
"test": "node test/example.js"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"postgresql",
|
|
15
|
+
"postgres",
|
|
16
|
+
"pg",
|
|
17
|
+
"database",
|
|
18
|
+
"driver",
|
|
19
|
+
"jsonb",
|
|
20
|
+
"schema-less",
|
|
21
|
+
"node-postgres",
|
|
22
|
+
"sql",
|
|
23
|
+
"lightweight",
|
|
24
|
+
"hawiah"
|
|
25
|
+
],
|
|
26
|
+
"author": "",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/Shuruhatik/hawiah-postgres.git"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/Shuruhatik/hawiah-postgres#readme",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/Shuruhatik/hawiah-postgres/issues"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"README.md",
|
|
39
|
+
"INSTALLATION.md",
|
|
40
|
+
"LICENSE"
|
|
41
|
+
],
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"pg": "^8.16.3"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/pg": "^8.11.10",
|
|
47
|
+
"@types/node": "^20.0.0",
|
|
48
|
+
"typescript": "^5.0.0"
|
|
49
|
+
}
|
|
50
|
+
}
|