pogi 3.0.0-beta → 3.0.0-beta5
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/.env +5 -0
- package/lib/bin/generateInterface.js +1 -1
- package/lib/connectionOptions.d.ts +7 -0
- package/lib/index.d.ts +1 -1
- package/lib/pgConverters.d.ts +9 -10
- package/lib/pgConverters.js +44 -39
- package/lib/pgConverters.js.map +1 -1
- package/lib/{src/pgConverters.test.d.ts → pgConverters.test.d.ts} +0 -0
- package/lib/{src/pgConverters.test.js → pgConverters.test.js} +0 -0
- package/lib/pgConverters.test.js.map +1 -0
- package/lib/pgDb.d.ts +24 -31
- package/lib/pgDb.js +66 -69
- package/lib/pgDb.js.map +1 -1
- package/lib/{src/pgDb.test.d.ts → pgDb.test.d.ts} +0 -0
- package/lib/{src/pgDb.test.js → pgDb.test.js} +6 -0
- package/lib/pgDb.test.js.map +1 -0
- package/lib/pgDbInterface.d.ts +22 -0
- package/lib/pgDbInterface.js +11 -0
- package/lib/pgDbInterface.js.map +1 -0
- package/lib/pgDbOperators.d.ts +3 -3
- package/lib/pgDbOperators.js +4 -7
- package/lib/pgDbOperators.js.map +1 -1
- package/lib/{src/pgDbOperators.test.d.ts → pgDbOperators.test.d.ts} +0 -0
- package/lib/{src/pgDbOperators.test.js → pgDbOperators.test.js} +0 -0
- package/lib/pgDbOperators.test.js.map +1 -0
- package/lib/pgSchema.d.ts +2 -3
- package/lib/pgSchema.js.map +1 -1
- package/lib/pgSchemaInterface.d.ts +0 -0
- package/lib/pgSchemaInterface.js +2 -0
- package/lib/pgSchemaInterface.js.map +1 -0
- package/lib/pgTable.d.ts +13 -38
- package/lib/pgTable.js +54 -54
- package/lib/pgTable.js.map +1 -1
- package/lib/pgTableInterface.d.ts +28 -0
- package/lib/{src/pgTableInterface.js → pgTableInterface.js} +0 -0
- package/lib/pgTableInterface.js.map +1 -0
- package/lib/pgUtils.d.ts +15 -5
- package/lib/pgUtils.js +118 -24
- package/lib/pgUtils.js.map +1 -1
- package/lib/queryAble.d.ts +15 -64
- package/lib/queryAble.js +46 -45
- package/lib/queryAble.js.map +1 -1
- package/lib/{src/queryAbleInterface.d.ts → queryAbleInterface.d.ts} +6 -10
- package/lib/{src/queryAbleInterface.js → queryAbleInterface.js} +0 -0
- package/lib/queryAbleInterface.js.map +1 -0
- package/lib/queryWhere.d.ts +2 -2
- package/lib/queryWhere.js +19 -23
- package/lib/queryWhere.js.map +1 -1
- package/lib/{src/bin/generateInterface.d.ts → test/pgDbOperatorSpec.d.ts} +0 -0
- package/lib/test/pgDbOperatorSpec.js +326 -0
- package/lib/test/pgDbOperatorSpec.js.map +1 -0
- package/lib/test/pgDbSpec.d.ts +1 -0
- package/lib/test/pgDbSpec.js +1139 -0
- package/lib/test/pgDbSpec.js.map +1 -0
- package/lib/test/pgServiceRestartTest.d.ts +1 -0
- package/lib/test/pgServiceRestartTest.js +1532 -0
- package/lib/test/pgServiceRestartTest.js.map +1 -0
- package/package.json +2 -1
- package/tsconfig.json +3 -5
- package/lib/src/bin/generateInterface.js +0 -53
- package/lib/src/bin/generateInterface.js.map +0 -1
- package/lib/src/connectionOptions.d.ts +0 -34
- package/lib/src/connectionOptions.js +0 -3
- package/lib/src/connectionOptions.js.map +0 -1
- package/lib/src/index.d.ts +0 -6
- package/lib/src/index.js +0 -12
- package/lib/src/index.js.map +0 -1
- package/lib/src/pgConverters.d.ts +0 -9
- package/lib/src/pgConverters.js +0 -71
- package/lib/src/pgConverters.js.map +0 -1
- package/lib/src/pgConverters.test.js.map +0 -1
- package/lib/src/pgDb.d.ts +0 -79
- package/lib/src/pgDb.js +0 -764
- package/lib/src/pgDb.js.map +0 -1
- package/lib/src/pgDb.test.js.map +0 -1
- package/lib/src/pgDbInterface.js +0 -11
- package/lib/src/pgDbInterface.js.map +0 -1
- package/lib/src/pgDbLogger.d.ts +0 -5
- package/lib/src/pgDbLogger.js +0 -3
- package/lib/src/pgDbLogger.js.map +0 -1
- package/lib/src/pgDbOperators.d.ts +0 -113
- package/lib/src/pgDbOperators.js +0 -41
- package/lib/src/pgDbOperators.js.map +0 -1
- package/lib/src/pgDbOperators.test.js.map +0 -1
- package/lib/src/pgSchema.d.ts +0 -17
- package/lib/src/pgSchema.js +0 -16
- package/lib/src/pgSchema.js.map +0 -1
- package/lib/src/pgSchemaInterface.d.ts +0 -12
- package/lib/src/pgSchemaInterface.js +0 -3
- package/lib/src/pgSchemaInterface.js.map +0 -1
- package/lib/src/pgTable.d.ts +0 -105
- package/lib/src/pgTable.js +0 -322
- package/lib/src/pgTable.js.map +0 -1
- package/lib/src/pgTableInterface.d.ts +0 -102
- package/lib/src/pgTableInterface.js.map +0 -1
- package/lib/src/pgUtils.d.ts +0 -41
- package/lib/src/pgUtils.js +0 -282
- package/lib/src/pgUtils.js.map +0 -1
- package/lib/src/queryAble.d.ts +0 -40
- package/lib/src/queryAble.js +0 -338
- package/lib/src/queryAble.js.map +0 -1
- package/lib/src/queryAbleInterface.js.map +0 -1
- package/lib/src/queryWhere.d.ts +0 -8
- package/lib/src/queryWhere.js +0 -245
- package/lib/src/queryWhere.js.map +0 -1
- package/src/bin/generateInterface.ts +0 -54
- package/src/connectionOptions.ts +0 -75
- package/src/index.d.ts +0 -7
- package/src/index.ts +0 -6
- package/src/pgConverters.test.ts +0 -10
- package/src/pgConverters.ts +0 -59
- package/src/pgDb.test.ts +0 -1324
- package/src/pgDb.ts +0 -842
- package/src/pgDbInterface.ts +0 -57
- package/src/pgDbLogger.ts +0 -13
- package/src/pgDbOperators.test.ts +0 -478
- package/src/pgDbOperators.ts +0 -85
- package/src/pgSchema.ts +0 -16
- package/src/pgSchemaInterface.ts +0 -12
- package/src/pgTable.ts +0 -369
- package/src/pgTableInterface.ts +0 -131
- package/src/pgUtils.ts +0 -290
- package/src/queryAble.ts +0 -365
- package/src/queryAbleInterface.ts +0 -108
- package/src/queryWhere.ts +0 -325
- package/src/test/init.sql +0 -122
- package/src/test/pgServiceRestartTest.ts +0 -1500
- package/src/test/throw_exception.sql +0 -5
- package/src/test/tricky.sql +0 -13
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import {PgDb} from "../pgDb";
|
|
2
|
-
import {PgSchema} from "../pgSchema";
|
|
3
|
-
import {PgTable} from "../pgTable";
|
|
4
|
-
|
|
5
|
-
(async function () {
|
|
6
|
-
try {
|
|
7
|
-
let pgdb = await PgDb.connect({
|
|
8
|
-
logger: {
|
|
9
|
-
log: () => {
|
|
10
|
-
}, error: console.error
|
|
11
|
-
}
|
|
12
|
-
}); //using PGUSER, PGPASSWORD + PGDATABASE env variables
|
|
13
|
-
|
|
14
|
-
console.log('import {PgDb, PgSchema, PgTable} from "pogi";\n');
|
|
15
|
-
console.log('export interface PgDbType extends PgDb {');
|
|
16
|
-
|
|
17
|
-
for (let schemaName in pgdb.schemas) {
|
|
18
|
-
if (!(pgdb[schemaName] instanceof PgSchema)) {
|
|
19
|
-
throw new Error('Already existing property: ' + schemaName + '!');
|
|
20
|
-
}
|
|
21
|
-
console.log(` '${schemaName}': PgSchema_${schemaName};`); //need to add a PgSchema_ prefix in order to handle schemas starting with number
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
console.log(` 'schemas': {`);
|
|
25
|
-
for (let schemaName in pgdb.schemas) {
|
|
26
|
-
console.log(` '${schemaName}': PgSchema_${schemaName};`);
|
|
27
|
-
}
|
|
28
|
-
console.log(' }');
|
|
29
|
-
console.log('}');
|
|
30
|
-
|
|
31
|
-
for (let schemaName in pgdb.schemas) {
|
|
32
|
-
console.log(`export interface PgSchema_${schemaName} extends PgSchema {`);
|
|
33
|
-
for (let tableName in pgdb.schemas[schemaName].tables) {
|
|
34
|
-
if (!(pgdb[schemaName][tableName] instanceof PgTable)) {
|
|
35
|
-
throw new Error('Already existing property: ' + tableName + ' on schema:' + schemaName + '!');
|
|
36
|
-
}
|
|
37
|
-
console.log(` '${tableName}': PgTable<any>;`);
|
|
38
|
-
}
|
|
39
|
-
console.log(` tables: {`);
|
|
40
|
-
for (let tableName in pgdb.schemas[schemaName].tables) {
|
|
41
|
-
console.log(` '${tableName}': PgTable<any>;`);
|
|
42
|
-
}
|
|
43
|
-
console.log(' }');
|
|
44
|
-
|
|
45
|
-
console.log('}');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
pgdb.close();
|
|
50
|
-
} catch (e) {
|
|
51
|
-
console.error(e);
|
|
52
|
-
}
|
|
53
|
-
return Promise.resolve();
|
|
54
|
-
})();
|
package/src/connectionOptions.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { PgDbLogger } from './pgDbLogger';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @property connectionString e.g.: "postgres://user@localhost/database"
|
|
5
|
-
* @property host can be specified through PGHOST env variable
|
|
6
|
-
* @property user can be specified through PGUSER env variable (defaults USER env var)
|
|
7
|
-
* @property database can be specified through PGDATABASE env variable (defaults USER env var)
|
|
8
|
-
* @property password can be specified through PGPASSWORD env variable
|
|
9
|
-
* @property port can be specified through PGPORT env variable
|
|
10
|
-
* @property idleTimeoutMillis how long a client is allowed to remain idle before being closed
|
|
11
|
-
* @property skipUndefined if there is a undefined value in the condition, what should pogi do. Default is 'none', meaning raise error if a value is undefined.
|
|
12
|
-
* @property logSQLDetailsOnError - log sql and params in case of sql error (this might contain sensitive information)
|
|
13
|
-
*/
|
|
14
|
-
export interface ConnectionOptions {
|
|
15
|
-
/** host can be specified through PGHOST env variable (defaults USER env var) */
|
|
16
|
-
host?: string;
|
|
17
|
-
/** user can be specified through PGUSER env variable (defaults USER env var) */
|
|
18
|
-
user?: string;
|
|
19
|
-
/** can be specified through PGDATABASE env variable (defaults USER env var) */
|
|
20
|
-
database?: string;
|
|
21
|
-
/** can be specified through PGPASSWORD env variable */
|
|
22
|
-
password?: string;
|
|
23
|
-
/** can be specified through PGPORT env variable */
|
|
24
|
-
port?: number;
|
|
25
|
-
poolSize?: number;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Turn on some basic sql injection protection
|
|
29
|
-
*/
|
|
30
|
-
forceEscapeColumns?: boolean | {
|
|
31
|
-
select?: boolean
|
|
32
|
-
where?: boolean
|
|
33
|
-
orderBy?: boolean
|
|
34
|
-
groupBy?: boolean
|
|
35
|
-
//warningOnly?: boolean
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
//number of rows to return at a time from a prepared statement's portal. 0 will return all rows at once
|
|
39
|
-
rows?: number;
|
|
40
|
-
/** set min pool size */
|
|
41
|
-
min?: number;
|
|
42
|
-
/** set pool max size */
|
|
43
|
-
max?: number;
|
|
44
|
-
|
|
45
|
-
binary?: boolean;
|
|
46
|
-
poolIdleTimeout?: number;
|
|
47
|
-
reapIntervalMillis?: number;
|
|
48
|
-
poolLog?: boolean;
|
|
49
|
-
client_encoding?: string;
|
|
50
|
-
ssl?: boolean | any; //| TlsOptions;
|
|
51
|
-
/** default:process.env.PGAPPNAME - name displayed in the pg_stat_activity view and included in CSV log entries */
|
|
52
|
-
application_name?: string;
|
|
53
|
-
fallback_application_name?: string;
|
|
54
|
-
parseInputDatesAsUTC?: boolean;
|
|
55
|
-
/** e.g.: "postgres://user@localhost/database" */
|
|
56
|
-
connectionString?: string;
|
|
57
|
-
/** how long a client is allowed to remain idle before being closed */
|
|
58
|
-
idleTimeoutMillis?: number;
|
|
59
|
-
|
|
60
|
-
logger?: PgDbLogger;
|
|
61
|
-
/** if there is a undefined value in the condition, what should pogi do. Default is 'none', meaning raise error if a value is undefined. */
|
|
62
|
-
skipUndefined?: 'all' | 'select' | 'none';
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* escape all ddl parameter (select, from, where, order by, group by, ...), default: true
|
|
66
|
-
* notes:
|
|
67
|
-
* - insert statements columns are always quoted
|
|
68
|
-
* - update statements "SET" columns are always quoted
|
|
69
|
-
* */
|
|
70
|
-
strictDdl?: boolean,
|
|
71
|
-
/** escape all "SELECT" ddl parameter, default: true */
|
|
72
|
-
strictDdlSelect?: boolean,
|
|
73
|
-
/** escape all "WHERE" ddl parameter, default: true */
|
|
74
|
-
strictDdlWhere?: boolean,
|
|
75
|
-
}
|
package/src/index.d.ts
DELETED
package/src/index.ts
DELETED
package/src/pgConverters.test.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { parseArray } from "./pgConverters";
|
|
2
|
-
|
|
3
|
-
describe("pgConverters.test", () => {
|
|
4
|
-
it("parseArray", async () => {
|
|
5
|
-
expect(parseArray('{}')).toEqual([]);
|
|
6
|
-
expect(parseArray('{1,2}')).toEqual(['1', '2']);
|
|
7
|
-
expect(parseArray('{NULL,""}')).toEqual([null, '']);
|
|
8
|
-
expect(parseArray('{"\\\\","\\""}')).toEqual(['\\', '"']);
|
|
9
|
-
});
|
|
10
|
-
});
|
package/src/pgConverters.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import * as moment from 'moment';
|
|
2
|
-
|
|
3
|
-
//--- add parsing for array types --------------------------------
|
|
4
|
-
export function parseArray(s: string): (string | null)[] {
|
|
5
|
-
if (!s || s[0] !== '{' || s[s.length - 1] !== '}') throw new Error('Invalid array value:' + s);
|
|
6
|
-
if (s == "{}") return [];
|
|
7
|
-
s = s.slice(1, s.length - 1); //cut off {}
|
|
8
|
-
let e = /(?:("(?:[^"\\]|\\.)*")|([^,"]*))(?:,|$)/g; //has to be mutable because of exec
|
|
9
|
-
let valList: (string | null)[] = [];
|
|
10
|
-
let parsingResult;
|
|
11
|
-
do {
|
|
12
|
-
parsingResult = e.exec(s);
|
|
13
|
-
if (!parsingResult) throw new Error('Invalid array value:' + s);
|
|
14
|
-
let valStr = (parsingResult[2] === 'NULL') ? null :
|
|
15
|
-
(parsingResult[1] == null ? parsingResult[2] : unescapeString(parsingResult[1])); // for string parsing, escape \
|
|
16
|
-
valList.push(valStr);
|
|
17
|
-
} while (e.lastIndex < s.length);
|
|
18
|
-
return valList;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export function parseNumberWithValidation(s: string): number | null {
|
|
22
|
-
if (s === 'NULL') {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
let v = +s;
|
|
26
|
-
if (v > Number.MAX_SAFE_INTEGER || v < Number.MIN_SAFE_INTEGER) {
|
|
27
|
-
throw new Error("Number can't be represented in javascript precisely: " + s);
|
|
28
|
-
}
|
|
29
|
-
return v;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export function parseNumberOrNull(s: string): number | null {
|
|
33
|
-
if (s === 'NULL') {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
return +s;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export function parseBoolOrNull(s: string): boolean | null {
|
|
40
|
-
if (s === 'NULL') {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
return s == 't';
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export let parseBooleanArray = (s: string): (boolean | null)[] => s == "{}" ? [] : s.substring(1, s.length - 1).split(',').map(parseBoolOrNull);
|
|
47
|
-
export let parseNumberArray = (s: string): (number | null)[] => s == "{}" ? [] : s.substring(1, s.length - 1).split(',').map(parseNumberOrNull);
|
|
48
|
-
export let parseNumberArrayWithValidation = (s: string[]) => s.map(parseNumberWithValidation);
|
|
49
|
-
export let parseDateArray = (s: string): (Date | null)[] => s == "{}" ? [] : s.substring(1, s.length - 1).split(',').map(d => d == 'NULL' ? null : moment(d.substring(1, d.length - 1)).toDate());
|
|
50
|
-
export let parseJsonArray = (s: string): (Object | null)[] => {
|
|
51
|
-
let vals = parseArray(s);
|
|
52
|
-
return vals.map(s2 => typeof s2 === 'string' ? JSON.parse(s2) : s2);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
function unescapeString(s: string): string {
|
|
56
|
-
return s.slice(1, s.length - 1) // cut the first and the last "
|
|
57
|
-
.replace(/\\"/g, '"') // \" -> "
|
|
58
|
-
.replace(/\\\\/g, '\\') // \\ -> \
|
|
59
|
-
}
|