@nymphjs/driver-postgresql 1.0.0-alpha.2

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/src/conf/d.ts ADDED
@@ -0,0 +1,37 @@
1
+ import type { PoolConfig } from 'pg';
2
+
3
+ /**
4
+ * PostgreSQL Driver Config
5
+ */
6
+ export interface PostgreSQLDriverConfig {
7
+ /**
8
+ * The host on which to connect to Postgres. Can include a port, like
9
+ * hostname:port.
10
+ */
11
+ host: string;
12
+ /**
13
+ * The port on which to connect to Postgres.
14
+ */
15
+ port: number;
16
+ /**
17
+ * The Postgres user.
18
+ */
19
+ user: string;
20
+ /**
21
+ * The Postgres password.
22
+ */
23
+ password: string;
24
+ /**
25
+ * The Postgres database.
26
+ */
27
+ database: string;
28
+ /**
29
+ * If you need to use custom options, like SSL, you can provide them here in
30
+ * place of the above options.
31
+ */
32
+ customPoolConfig: PoolConfig | null;
33
+ /**
34
+ * The Postgres table name prefix.
35
+ */
36
+ prefix: string;
37
+ }
@@ -0,0 +1,11 @@
1
+ import { PostgreSQLDriverConfig } from './d';
2
+
3
+ export default {
4
+ host: 'localhost',
5
+ port: 5432,
6
+ user: 'nymph',
7
+ password: 'password',
8
+ database: 'nymph',
9
+ customPoolConfig: null,
10
+ prefix: 'nymph_',
11
+ } as PostgreSQLDriverConfig;
@@ -0,0 +1,4 @@
1
+ export { PostgreSQLDriverConfig } from './d';
2
+
3
+ import defaults from './defaults';
4
+ export { defaults as PostgreSQLDriverConfigDefaults };
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './conf';
2
+
3
+ import PostgreSQLDriver from './PostgreSQLDriver';
4
+ export { PostgreSQLDriver };
5
+ export default PostgreSQLDriver;
@@ -0,0 +1,35 @@
1
+ const pg = require('pg');
2
+
3
+ let stdin = '';
4
+
5
+ process.stdin.on('data', (data) => {
6
+ if (data != null) {
7
+ stdin += data.toString();
8
+ }
9
+ });
10
+
11
+ process.stdin.on('end', () => {
12
+ run();
13
+ });
14
+
15
+ async function run() {
16
+ try {
17
+ const { postgresqlConfig, query, params } = JSON.parse(stdin);
18
+ const pool = new pg.Pool(postgresqlConfig);
19
+ const results = await new Promise((resolve, reject) =>
20
+ pool.query(query, params).then(
21
+ (results) => resolve(results),
22
+ (error) => reject(error)
23
+ )
24
+ );
25
+ process.stdout.end(JSON.stringify(results), 'utf8', () => {
26
+ pool.end(() => {
27
+ process.exit(0);
28
+ });
29
+ });
30
+ } catch (e) {
31
+ process.stderr.end(JSON.stringify(e), 'utf8', () => {
32
+ process.exit(1);
33
+ });
34
+ }
35
+ }
@@ -0,0 +1,59 @@
1
+ const cp = require('child_process');
2
+
3
+ const postgresqlConfig = {
4
+ host: 'localhost',
5
+ user: 'nymph',
6
+ password: 'nymph',
7
+ database: 'nymph',
8
+ insecureAuth: true,
9
+ };
10
+
11
+ const guid = '790274347f9b3a018c2cedee';
12
+ const guidBuf = Buffer.from(guid, 'hex');
13
+
14
+ // const query = 'SELECT $1 AS message;';
15
+ // const params = ['Hello, world.'];
16
+
17
+ const query = 'SELECT $1 AS message;';
18
+ const params = [['Hello, world.']];
19
+
20
+ // const query = "SELECT encode(decode($1, 'hex'), 'hex') AS message;";
21
+ // const params = [guid];
22
+
23
+ // const query = 'CREATE TABLE test ("id" INT NOT NULL, PRIMARY KEY ("id"));';
24
+ // const params = [];
25
+
26
+ // const query = 'CREATE TABLE test ("id" BYTEA NOT NULL, PRIMARY KEY ("id"));';
27
+ // const params = [];
28
+
29
+ // const query = 'INSERT INTO test ( "id" ) VALUES ( decode($1, \'hex\') );';
30
+ // const params = [guid];
31
+
32
+ // const query = 'SELECT encode("id", \'hex\') as "id" FROM test;';
33
+ // const params = [];
34
+
35
+ // const query = 'SELECT * FROM nonexist;';
36
+ // const params = [];
37
+
38
+ // const query = 'SELECT relname FROM pg_stat_user_tables ORDER BY relname;';
39
+ // const params = [];
40
+
41
+ const output = cp.spawnSync(
42
+ process.argv0,
43
+ [__dirname + '/runPostgresqlSync.js'],
44
+ {
45
+ input: JSON.stringify({ postgresqlConfig, query, params }),
46
+ timeout: 30000,
47
+ maxBuffer: 100 * 1024 * 1024,
48
+ encoding: 'utf8',
49
+ windowsHide: true,
50
+ }
51
+ );
52
+ try {
53
+ const result = JSON.parse(output.stdout);
54
+ console.log('Server reply: ', result);
55
+ } catch (e) {
56
+ // Do nothing.
57
+ }
58
+ const err = output.status === 0 ? null : JSON.parse(output.stderr);
59
+ if (err) console.error(err);
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "extends": "@tsconfig/recommended/tsconfig.json",
3
+
4
+ "compilerOptions": {
5
+ "noImplicitAny": true,
6
+ "removeComments": true,
7
+ "sourceMap": true,
8
+ "outDir": "dist",
9
+ "resolveJsonModule": true,
10
+ "rootDir": "src/",
11
+ "declaration": true
12
+ },
13
+ "include": ["src/**/*"],
14
+ "exclude": ["node_modules", "**/*.spec.ts"]
15
+ }