@zintrust/db-postgres 0.1.19 → 0.1.21

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/README.md CHANGED
@@ -34,3 +34,7 @@ DB_CONNECTION=postgresql
34
34
 
35
35
  - https://zintrust.com/adapters
36
36
  - https://zintrust.com/database-advanced
37
+
38
+ ## License
39
+
40
+ This package and its dependencies are MIT licensed, permitting free commercial use.
package/dist/index.d.ts CHANGED
@@ -21,6 +21,7 @@ export interface IDatabaseAdapter {
21
21
  ping(): Promise<void>;
22
22
  transaction<T>(callback: (adapter: IDatabaseAdapter) => Promise<T>): Promise<T>;
23
23
  rawQuery<T = unknown>(sql: string, parameters?: unknown[]): Promise<T[]>;
24
+ ensureMigrationsTable?(): Promise<void>;
24
25
  getType(): string;
25
26
  isConnected(): boolean;
26
27
  getPlaceholder(index: number): string;
package/dist/index.js CHANGED
@@ -68,7 +68,13 @@ async function disconnect(state) {
68
68
  async function query(state, sql, parameters) {
69
69
  const current = ensurePool(state);
70
70
  try {
71
- const result = await current.query(sql, parameters);
71
+ // Convert ? placeholders to PostgreSQL's $1, $2, etc format
72
+ let paramIndex = 0;
73
+ const processedSql = sql.replaceAll('?', () => {
74
+ paramIndex++;
75
+ return `$${paramIndex}`;
76
+ });
77
+ const result = await current.query(processedSql, parameters);
72
78
  return {
73
79
  rows: (result.rows ?? []),
74
80
  rowCount: result.rowCount ?? result.rows?.length ?? 0,
@@ -114,6 +120,19 @@ function createPostgresAdapter(config) {
114
120
  },
115
121
  transaction: async (callback) => transaction(state, adapter, callback),
116
122
  rawQuery: async (sql, parameters) => rawQuery(adapter, sql, parameters),
123
+ ensureMigrationsTable: async () => {
124
+ await adapter.query(`CREATE TABLE IF NOT EXISTS migrations (
125
+ id SERIAL PRIMARY KEY,
126
+ name VARCHAR(255) NOT NULL,
127
+ scope VARCHAR(255) NOT NULL DEFAULT 'global',
128
+ service VARCHAR(255) NOT NULL DEFAULT '',
129
+ batch INTEGER NOT NULL,
130
+ status VARCHAR(255) NOT NULL,
131
+ applied_at TIMESTAMP NULL,
132
+ created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
133
+ UNIQUE(name, scope, service)
134
+ )`, []);
135
+ },
117
136
  getType: () => 'postgresql',
118
137
  isConnected: () => state.connected,
119
138
  getPlaceholder: (index) => `$${index}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zintrust/db-postgres",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -22,7 +22,7 @@
22
22
  "node": ">=20.0.0"
23
23
  },
24
24
  "peerDependencies": {
25
- "@zintrust/core": "^0.1.19"
25
+ "@zintrust/core": "^0.1.21"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public"