@depup/pg-mem 3.0.14-depup.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/README.md +35 -0
- package/changes.json +26 -0
- package/index.d.ts +1 -0
- package/index.js +16547 -0
- package/index.js.map +1 -0
- package/package.json +196 -0
- package/readme.md +297 -0
- package/types/adapters/adapters.d.ts +37 -0
- package/types/adapters/index.d.ts +2 -0
- package/types/adapters/pg-socket-adapter.d.ts +30 -0
- package/types/column.d.ts +27 -0
- package/types/constraints/foreign-key.d.ts +14 -0
- package/types/constraints/generated-from-expr.d.ts +14 -0
- package/types/constraints/generated-identity.d.ts +13 -0
- package/types/constraints/index-cst.d.ts +9 -0
- package/types/constraints/subscription.d.ts +7 -0
- package/types/constraints/wrapped.d.ts +9 -0
- package/types/datatypes/datatype-base.d.ts +66 -0
- package/types/datatypes/datatypes-geometric.d.ts +59 -0
- package/types/datatypes/datatypes-geometric.spec.d.ts +2 -0
- package/types/datatypes/datatypes.d.ts +101 -0
- package/types/datatypes/index.d.ts +2 -0
- package/types/datatypes/t-custom-enum.d.ts +21 -0
- package/types/datatypes/t-equivalent.d.ts +18 -0
- package/types/datatypes/t-inet.d.ts +13 -0
- package/types/datatypes/t-interval.d.ts +13 -0
- package/types/datatypes/t-jsonb.d.ts +16 -0
- package/types/datatypes/t-record.d.ts +17 -0
- package/types/datatypes/t-regclass.d.ts +11 -0
- package/types/datatypes/t-regtype.d.ts +11 -0
- package/types/datatypes/t-time.d.ts +14 -0
- package/types/datatypes/t-timestamp.d.ts +18 -0
- package/types/db.d.ts +3 -0
- package/types/evaluator.d.ts +61 -0
- package/types/execution/clean-results.d.ts +5 -0
- package/types/execution/exec-utils.d.ts +19 -0
- package/types/execution/records-mutations/deletion.d.ts +8 -0
- package/types/execution/records-mutations/insert.d.ts +13 -0
- package/types/execution/records-mutations/mutation-base.d.ts +31 -0
- package/types/execution/records-mutations/truncate-table.d.ts +10 -0
- package/types/execution/records-mutations/update.d.ts +10 -0
- package/types/execution/schema-amends/alter-enum.d.ts +20 -0
- package/types/execution/schema-amends/alter-sequence.d.ts +19 -0
- package/types/execution/schema-amends/alter.d.ts +19 -0
- package/types/execution/schema-amends/comment.d.ts +19 -0
- package/types/execution/schema-amends/create-enum.d.ts +20 -0
- package/types/execution/schema-amends/create-function.d.ts +20 -0
- package/types/execution/schema-amends/create-index.d.ts +19 -0
- package/types/execution/schema-amends/create-materialized-view.d.ts +19 -0
- package/types/execution/schema-amends/create-schema.d.ts +19 -0
- package/types/execution/schema-amends/create-sequence.d.ts +21 -0
- package/types/execution/schema-amends/create-table.d.ts +21 -0
- package/types/execution/schema-amends/create-view.d.ts +22 -0
- package/types/execution/schema-amends/do.d.ts +9 -0
- package/types/execution/schema-amends/drop-index.d.ts +18 -0
- package/types/execution/schema-amends/drop-sequence.d.ts +18 -0
- package/types/execution/schema-amends/drop-table.d.ts +19 -0
- package/types/execution/schema-amends/drop-type.d.ts +18 -0
- package/types/execution/select.d.ts +15 -0
- package/types/execution/set.d.ts +9 -0
- package/types/execution/show.d.ts +8 -0
- package/types/execution/statement-exec.d.ts +26 -0
- package/types/execution/transaction-statements.d.ts +16 -0
- package/types/functions/date.d.ts +3 -0
- package/types/functions/index.d.ts +2 -0
- package/types/functions/numbers.d.ts +3 -0
- package/types/functions/sequence-fns.d.ts +3 -0
- package/types/functions/string.d.ts +3 -0
- package/types/functions/subquery.d.ts +3 -0
- package/types/functions/system.d.ts +3 -0
- package/types/index.d.ts +5 -0
- package/types/interfaces-private.d.ts +605 -0
- package/types/interfaces.d.ts +449 -0
- package/types/migrate/migrate-interfaces.d.ts +32 -0
- package/types/migrate/migrate.d.ts +8 -0
- package/types/misc/buffer-deno.d.ts +7 -0
- package/types/misc/buffer-node.d.ts +7 -0
- package/types/misc/pg-escape.d.ts +2 -0
- package/types/misc/pg-utils.d.ts +3 -0
- package/types/parser/context.d.ts +26 -0
- package/types/parser/expression-builder.d.ts +8 -0
- package/types/parser/function-call.d.ts +4 -0
- package/types/parser/parse-cache.d.ts +6 -0
- package/types/schema/btree-index.d.ts +48 -0
- package/types/schema/consts.d.ts +10 -0
- package/types/schema/custom-index.d.ts +31 -0
- package/types/schema/function-call-table.d.ts +20 -0
- package/types/schema/information-schema/columns-list.d.ts +13 -0
- package/types/schema/information-schema/constraint-column-usage.d.ts +10 -0
- package/types/schema/information-schema/index.d.ts +3 -0
- package/types/schema/information-schema/key-column-usage.d.ts +10 -0
- package/types/schema/information-schema/table-constraints.d.ts +10 -0
- package/types/schema/information-schema/table-list.d.ts +14 -0
- package/types/schema/overload-resolver.d.ts +17 -0
- package/types/schema/pg-catalog/binary-operators.d.ts +3 -0
- package/types/schema/pg-catalog/index.d.ts +3 -0
- package/types/schema/pg-catalog/pg-attribute-list.d.ts +11 -0
- package/types/schema/pg-catalog/pg-class.d.ts +13 -0
- package/types/schema/pg-catalog/pg-constraints-list.d.ts +13 -0
- package/types/schema/pg-catalog/pg-database.d.ts +17 -0
- package/types/schema/pg-catalog/pg-enum-list.d.ts +10 -0
- package/types/schema/pg-catalog/pg-index-list.d.ts +10 -0
- package/types/schema/pg-catalog/pg-namespace-list.d.ts +10 -0
- package/types/schema/pg-catalog/pg-proc.d.ts +10 -0
- package/types/schema/pg-catalog/pg-range.d.ts +10 -0
- package/types/schema/pg-catalog/pg-sequences-list.d.ts +10 -0
- package/types/schema/pg-catalog/pg-type-list.d.ts +10 -0
- package/types/schema/pg-catalog/pg-user-list.d.ts +10 -0
- package/types/schema/pg-catalog/pg_statio_user_tables.d.ts +25 -0
- package/types/schema/pg-catalog/sql-function-language.d.ts +3 -0
- package/types/schema/prepared-intercepted.d.ts +11 -0
- package/types/schema/prepared.d.ts +5 -0
- package/types/schema/readonly-table.d.ts +62 -0
- package/types/schema/schema.d.ts +73 -0
- package/types/schema/sequence.d.ts +27 -0
- package/types/schema/table-index.d.ts +32 -0
- package/types/schema/values-table.d.ts +16 -0
- package/types/schema/view.d.ts +18 -0
- package/types/table.d.ts +97 -0
- package/types/transaction.d.ts +26 -0
- package/types/transforms/aggregation.d.ts +41 -0
- package/types/transforms/aggregations/array_agg.d.ts +11 -0
- package/types/transforms/aggregations/avg.d.ts +11 -0
- package/types/transforms/aggregations/bool-aggregs.d.ts +12 -0
- package/types/transforms/aggregations/count.d.ts +19 -0
- package/types/transforms/aggregations/json_aggs.d.ts +11 -0
- package/types/transforms/aggregations/max-min.d.ts +12 -0
- package/types/transforms/aggregations/sum.d.ts +11 -0
- package/types/transforms/alias.d.ts +29 -0
- package/types/transforms/and-filter.d.ts +15 -0
- package/types/transforms/array-filter.d.ts +14 -0
- package/types/transforms/between-filter.d.ts +16 -0
- package/types/transforms/build-filter.d.ts +4 -0
- package/types/transforms/distinct.d.ts +16 -0
- package/types/transforms/eq-filter.d.ts +17 -0
- package/types/transforms/false-filter.d.ts +11 -0
- package/types/transforms/in-filter.d.ts +14 -0
- package/types/transforms/ineq-filter.d.ts +16 -0
- package/types/transforms/join.d.ts +74 -0
- package/types/transforms/limit.d.ts +18 -0
- package/types/transforms/not-in-filter.d.ts +15 -0
- package/types/transforms/or-filter.d.ts +13 -0
- package/types/transforms/order-by.d.ts +26 -0
- package/types/transforms/restrictive-index.d.ts +15 -0
- package/types/transforms/selection.d.ts +45 -0
- package/types/transforms/seq-scan.d.ts +14 -0
- package/types/transforms/startswith-filter.d.ts +14 -0
- package/types/transforms/transform-base.d.ts +100 -0
- package/types/transforms/union.d.ts +32 -0
- package/types/utils.d.ts +86 -0
package/package.json
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@depup/pg-mem",
|
|
3
|
+
"version": "3.0.14-depup.0",
|
|
4
|
+
"description": "A memory version of postgres (with updated dependencies)",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "rimraf lib && NODE_OPTIONS=--openssl-legacy-provider webpack --config ./tools/webpack.config.js --prod && bun build-types",
|
|
8
|
+
"build-types": "rimraf lib/types && tsc --project tsconfig.json && copyfiles -u 2 \"lib-types/src/**/*.ts\" lib/types && rimraf lib/types/tests && rimraf lib-types && echo \"export * from './types';\" >> lib/index.d.ts",
|
|
9
|
+
"release": "bun release-node && bun release-deno",
|
|
10
|
+
"release-node": "git diff --exit-code && bun test && bun run build && bun build:deno && deno run tools/deno-test.ts && cd lib && npm publish && cd ..",
|
|
11
|
+
"release-deno": "git add -A && git commit -m \"Build deno [autogenerated commit]\" && PACKAGE_VERSION=$(cat package.json | grep \\\"version\\\" | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') && git tag $PACKAGE_VERSION && git push --tags",
|
|
12
|
+
"start:playground": "NODE_OPTIONS=--openssl-legacy-provider webpack-dev-server --hot --config ./tools/playground.webpack.config.js",
|
|
13
|
+
"build:playground": "NODE_OPTIONS=--openssl-legacy-provider webpack --config ./tools/playground.webpack.config.js --prod",
|
|
14
|
+
"release:playground": "bun build:playground && cd dist && git init && git add -A && git commit -m\"initial\" && git remote add origin git@github.com:oguimbal/pg-mem-playground.git && git push --set-upstream origin master --force",
|
|
15
|
+
"typecheck": "tsc --project tsconfig.json --noEmit",
|
|
16
|
+
"test": "bun test",
|
|
17
|
+
"build:deno": "node ./tools/deno-transpile.js --copy && node ./tools/deno-transpile.js --process",
|
|
18
|
+
"cover": "NODE_OPTIONS=--openssl-legacy-provider cross-env NODE_ENV=coverage nyc --reporter=lcov --reporter=text bun test"
|
|
19
|
+
},
|
|
20
|
+
"author": "Olivier Guimbal",
|
|
21
|
+
"repository": "https://github.com/oguimbal/pg-mem",
|
|
22
|
+
"issues": "https://github.com/oguimbal/pg-mem/issues",
|
|
23
|
+
"keywords": [
|
|
24
|
+
"pg-mem",
|
|
25
|
+
"depup",
|
|
26
|
+
"updated-dependencies",
|
|
27
|
+
"security",
|
|
28
|
+
"latest",
|
|
29
|
+
"patched",
|
|
30
|
+
"postgres",
|
|
31
|
+
"pg-mock",
|
|
32
|
+
"mock",
|
|
33
|
+
"memory",
|
|
34
|
+
"db",
|
|
35
|
+
"database",
|
|
36
|
+
"pg",
|
|
37
|
+
"typeorm",
|
|
38
|
+
"pg-promise",
|
|
39
|
+
"pg-native",
|
|
40
|
+
"unit test",
|
|
41
|
+
"ut",
|
|
42
|
+
"sql",
|
|
43
|
+
"pgsql",
|
|
44
|
+
"postgresql",
|
|
45
|
+
"knex",
|
|
46
|
+
"kysely"
|
|
47
|
+
],
|
|
48
|
+
"license": "MIT",
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"functional-red-black-tree": "^1.0.1",
|
|
51
|
+
"immutable": "^5.1.5",
|
|
52
|
+
"json-stable-stringify": "^1.3.0",
|
|
53
|
+
"lru-cache": "^11.2.7",
|
|
54
|
+
"moment": "^2.30.1",
|
|
55
|
+
"object-hash": "^3.0.0",
|
|
56
|
+
"pgsql-ast-parser": "^12.0.2"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@babel/cli": "^7.10.5",
|
|
60
|
+
"@babel/core": "^7.10.5",
|
|
61
|
+
"@babel/preset-env": "^7.10.4",
|
|
62
|
+
"@hot-loader/react-dom": "^16.13.0",
|
|
63
|
+
"@mikro-orm/core": "^5.8.1",
|
|
64
|
+
"@mikro-orm/postgresql": "^5.8.1",
|
|
65
|
+
"@types/json-stable-stringify": "^1.0.34",
|
|
66
|
+
"@types/lru-cache": "^5.1.0",
|
|
67
|
+
"@types/node": "^16.18.69",
|
|
68
|
+
"@types/object-hash": "^1.3.3",
|
|
69
|
+
"@types/pg": "^7.14.9",
|
|
70
|
+
"@types/react": "^16.9.43",
|
|
71
|
+
"@types/uuid": "^8.3.0",
|
|
72
|
+
"babel": "^6.23.0",
|
|
73
|
+
"babel-loader": "^8.1.0",
|
|
74
|
+
"babel-preset-react-app": "^9.1.2",
|
|
75
|
+
"bun-types": "^1.1.21",
|
|
76
|
+
"copy-webpack-plugin": "^6.0.3",
|
|
77
|
+
"copyfiles": "^2.4.0",
|
|
78
|
+
"cross-env": "^7.0.2",
|
|
79
|
+
"css-loader": "^4.1.0",
|
|
80
|
+
"dedent": "^0.7.0",
|
|
81
|
+
"file-loader": "^6.0.0",
|
|
82
|
+
"html-webpack-plugin": "^4.3.0",
|
|
83
|
+
"istanbul-instrumenter-loader": "^2.0.0",
|
|
84
|
+
"knex": "^2.5.1",
|
|
85
|
+
"kysely": "^0.26.3",
|
|
86
|
+
"monaco-editor": "^0.20.0",
|
|
87
|
+
"monaco-editor-webpack-plugin": "^1.9.0",
|
|
88
|
+
"nyc": "^15.1.0",
|
|
89
|
+
"pg": "^8.5.1",
|
|
90
|
+
"pg-promise": "^10.8.7",
|
|
91
|
+
"pg-server": "0.1.8",
|
|
92
|
+
"postgres": "^3.4.4",
|
|
93
|
+
"react": "^16.13.1",
|
|
94
|
+
"react-dom": "^16.13.1",
|
|
95
|
+
"react-hot-loader": "^4.12.21",
|
|
96
|
+
"react-monaco-editor": "^0.39.1",
|
|
97
|
+
"reactjs-popup": "^1.5.0",
|
|
98
|
+
"rimraf": "^3.0.2",
|
|
99
|
+
"sequelize": ">=6.3.5 <6.20.0",
|
|
100
|
+
"slonik": "45.6.0",
|
|
101
|
+
"source-map-support": "^0.5.19",
|
|
102
|
+
"style-loader": "^1.2.1",
|
|
103
|
+
"ts-loader": "^8.0.0",
|
|
104
|
+
"ts-node": "^10.8.0",
|
|
105
|
+
"typeorm": "0.2.29",
|
|
106
|
+
"typescript": "^5.5.4",
|
|
107
|
+
"uuid": "^8.3.2",
|
|
108
|
+
"webpack": "4.43.0",
|
|
109
|
+
"webpack-cli": "3.3.12",
|
|
110
|
+
"webpack-dev-server": "4.9.2",
|
|
111
|
+
"webpack-node-externals": "^1.7.2",
|
|
112
|
+
"zod": "^3.23.8"
|
|
113
|
+
},
|
|
114
|
+
"peerDependencies": {
|
|
115
|
+
"@mikro-orm/core": ">=4.5.3",
|
|
116
|
+
"@mikro-orm/postgresql": ">=4.5.3",
|
|
117
|
+
"knex": ">=0.20",
|
|
118
|
+
"kysely": ">=0.26",
|
|
119
|
+
"pg-promise": ">=10.8.7",
|
|
120
|
+
"slonik": ">=23.0.1",
|
|
121
|
+
"typeorm": ">=0.2.29",
|
|
122
|
+
"postgres": "^3.4.4",
|
|
123
|
+
"pg-server": "^0.1.5"
|
|
124
|
+
},
|
|
125
|
+
"peerDependenciesMeta": {
|
|
126
|
+
"pg-server": {
|
|
127
|
+
"optional": true
|
|
128
|
+
},
|
|
129
|
+
"postgres": {
|
|
130
|
+
"optional": true
|
|
131
|
+
},
|
|
132
|
+
"@mikro-orm/core": {
|
|
133
|
+
"optional": true
|
|
134
|
+
},
|
|
135
|
+
"@mikro-orm/postgresql": {
|
|
136
|
+
"optional": true
|
|
137
|
+
},
|
|
138
|
+
"pg-promise": {
|
|
139
|
+
"optional": true
|
|
140
|
+
},
|
|
141
|
+
"typeorm": {
|
|
142
|
+
"optional": true
|
|
143
|
+
},
|
|
144
|
+
"slonik": {
|
|
145
|
+
"optional": true
|
|
146
|
+
},
|
|
147
|
+
"knex": {
|
|
148
|
+
"optional": true
|
|
149
|
+
},
|
|
150
|
+
"kysely": {
|
|
151
|
+
"optional": true
|
|
152
|
+
},
|
|
153
|
+
"mikro-orm": {
|
|
154
|
+
"optional": true
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
"nyc": {
|
|
158
|
+
"include": [
|
|
159
|
+
"src/**/*.ts"
|
|
160
|
+
],
|
|
161
|
+
"exclude": [
|
|
162
|
+
"src/**/*.spec.ts"
|
|
163
|
+
],
|
|
164
|
+
"instrument": false,
|
|
165
|
+
"sourceMap": false
|
|
166
|
+
},
|
|
167
|
+
"depup": {
|
|
168
|
+
"changes": {
|
|
169
|
+
"immutable": {
|
|
170
|
+
"from": "^4.3.4",
|
|
171
|
+
"to": "^5.1.5"
|
|
172
|
+
},
|
|
173
|
+
"json-stable-stringify": {
|
|
174
|
+
"from": "^1.0.1",
|
|
175
|
+
"to": "^1.3.0"
|
|
176
|
+
},
|
|
177
|
+
"lru-cache": {
|
|
178
|
+
"from": "^6.0.0",
|
|
179
|
+
"to": "^11.2.7"
|
|
180
|
+
},
|
|
181
|
+
"moment": {
|
|
182
|
+
"from": "^2.27.0",
|
|
183
|
+
"to": "^2.30.1"
|
|
184
|
+
},
|
|
185
|
+
"object-hash": {
|
|
186
|
+
"from": "^2.0.3",
|
|
187
|
+
"to": "^3.0.0"
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
"depsUpdated": 5,
|
|
191
|
+
"originalPackage": "pg-mem",
|
|
192
|
+
"originalVersion": "3.0.14",
|
|
193
|
+
"processedAt": "2026-03-19T03:04:37.001Z",
|
|
194
|
+
"smokeTest": "failed"
|
|
195
|
+
}
|
|
196
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://npmjs.org/package/pg-mem"><img src="http://img.shields.io/npm/v/pg-mem.svg"></a>
|
|
3
|
+
<a href="https://npmjs.org/package/pg-mem"><img src="https://img.shields.io/npm/dm/pg-mem.svg"></a>
|
|
4
|
+
<a href="https://david-dm.org/oguimbal/pg-mem"><img src="https://david-dm.org/oguimbal/pg-mem.svg"></a>
|
|
5
|
+
<img src="https://github.com/oguimbal/pg-mem/workflows/CI/badge.svg">
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<img src="./.github/pg_mem.png" width="200">
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
<h3 align="center">pg-mem is an experimental in-memory emulation of a postgres database.</h3>
|
|
13
|
+
|
|
14
|
+
<p align="center">
|
|
15
|
+
❤ It works both in Node or in the browser.
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
<p align="center">
|
|
19
|
+
⭐ this repo if you like this package, it helps to motivate me :)
|
|
20
|
+
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
<p align="center">
|
|
24
|
+
👉 See it in action with <a href="https://oguimbal.github.io/pg-mem-playground/">pg-mem playground</a>
|
|
25
|
+
</p>
|
|
26
|
+
|
|
27
|
+
- [Usage](#-usage)
|
|
28
|
+
- [Features](#-features)
|
|
29
|
+
- [Libraries adapters](#-libraries-adapters)
|
|
30
|
+
- [Inspection](#-inspection)
|
|
31
|
+
- [Development](#-development)
|
|
32
|
+
- [FAQ](https://github.com/oguimbal/pg-mem/wiki/FAQ)
|
|
33
|
+
|
|
34
|
+
# 📐 Usage
|
|
35
|
+
|
|
36
|
+
## Using Node.js
|
|
37
|
+
|
|
38
|
+
As always, it starts with an:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm i pg-mem --save
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Then, assuming you're using something like webpack, if you're targeting a browser:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { newDb } from "pg-mem";
|
|
48
|
+
|
|
49
|
+
const db = newDb();
|
|
50
|
+
db.public.many(/* put some sql here */);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Using Deno
|
|
54
|
+
|
|
55
|
+
Pretty straightforward :)
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { newDb } from "https://deno.land/x/pg_mem/mod.ts";
|
|
59
|
+
|
|
60
|
+
const db = newDb();
|
|
61
|
+
db.public.many(/* put some sql here */);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Only use the SQL syntax parser
|
|
65
|
+
|
|
66
|
+
❤ Head to the [pgsql-ast-parser](https://github.com/oguimbal/pgsql-ast-parser) repo
|
|
67
|
+
|
|
68
|
+
## ⚠ Disclaimer
|
|
69
|
+
|
|
70
|
+
The sql syntax parser is [home-made](https://github.com/oguimbal/pgsql-ast-parser). Which means that some features are not implemented, and will be considered as invalid syntaxes.
|
|
71
|
+
|
|
72
|
+
This lib is quite new, so forgive it if some obvious pg syntax is not supported !
|
|
73
|
+
|
|
74
|
+
... And open an issue if you feel like a feature should be implemented :)
|
|
75
|
+
|
|
76
|
+
Moreover, even if I wrote hundreds of tests, keep in mind that this implementation is a best effort to replicate PG.
|
|
77
|
+
Keep an eye on your query results if you perform complex queries.
|
|
78
|
+
Please file issues if some results seem incoherent with what should be returned.
|
|
79
|
+
|
|
80
|
+
Finally, I invite you to read the below section to have an idea of you can or cannot do.
|
|
81
|
+
|
|
82
|
+
# 🔍 Features
|
|
83
|
+
|
|
84
|
+
## Rollback to a previous state
|
|
85
|
+
|
|
86
|
+
`pg-mem` uses immutable data structures ([here](https://www.npmjs.com/package/immutable) and [here](https://www.npmjs.com/package/functional-red-black-tree)),
|
|
87
|
+
which means that you can have restore points for free!
|
|
88
|
+
|
|
89
|
+
This is super useful if you intend to use `pg-mem` to mock your database for unit tests.
|
|
90
|
+
|
|
91
|
+
You could:
|
|
92
|
+
|
|
93
|
+
1. Create your schema only once (which could be a heavy operation for a single unit test)
|
|
94
|
+
2. Insert test data which will be shared by all test
|
|
95
|
+
3. Create a restore point
|
|
96
|
+
4. Run your tests with the same db instance, executing a `backup.restore()` before each test (which instantly resets db to the state it has after creating the restore point)
|
|
97
|
+
|
|
98
|
+
Usage:
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
const db = newDb();
|
|
102
|
+
db.public.none(`create table test(id text);
|
|
103
|
+
insert into test values ('value');`);
|
|
104
|
+
// create a restore point & mess with data
|
|
105
|
+
const backup = db.backup();
|
|
106
|
+
db.public.none(`update test set id='new value';`);
|
|
107
|
+
// restore it !
|
|
108
|
+
backup.restore();
|
|
109
|
+
db.public.many(`select * from test`); // => {test: 'value'}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Custom functions
|
|
113
|
+
|
|
114
|
+
You can declare custom functions like this:
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
db.public.registerFunction({
|
|
118
|
+
name: "say_hello",
|
|
119
|
+
args: [DataType.text],
|
|
120
|
+
returns: DataType.text,
|
|
121
|
+
implementation: (x) => "hello " + x,
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
And then use them like in SQL `select say_hello('world')`.
|
|
126
|
+
|
|
127
|
+
Custom functions support overloading and variadic arguments.
|
|
128
|
+
|
|
129
|
+
⚠ However, the value you return is not type checked. It MUST correspond to the datatype you provided as 'returns' (it won't fail if not, but could lead to weird bugs).
|
|
130
|
+
|
|
131
|
+
## Custom types
|
|
132
|
+
|
|
133
|
+
Not all pg types are implemented in pg-mem.
|
|
134
|
+
That said, most of the types are often equivalent to other types, with a format validation. pg-mem provides a way to register such types.
|
|
135
|
+
|
|
136
|
+
For instance, lets say you'd like to register the MACADDR type, which is basically a string, with a format constraint.
|
|
137
|
+
|
|
138
|
+
You can register it like this:
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
db.public.registerEquivalentType({
|
|
142
|
+
name: "macaddr",
|
|
143
|
+
// which type is it equivalent to (will be able to cast it from it)
|
|
144
|
+
equivalentTo: DataType.text,
|
|
145
|
+
isValid(val: string) {
|
|
146
|
+
// check that it will be this format
|
|
147
|
+
return isValidMacAddress(val);
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Doing so, you'll be able to do things such as:
|
|
153
|
+
|
|
154
|
+
```sql
|
|
155
|
+
SELECT '08:00:2b:01:02:03:04:05'::macaddr; -- WORKS
|
|
156
|
+
SELECT 'invalid'::macaddr; -- will throw a conversion error
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
If you feel your implementation of a type matches the standard, and would like to include it in pg-mem for others to enjoy it, please consider filing a pull request ! (tip: see the [INET](https://github.com/oguimbal/pg-mem/blob/master/src/datatypes/t-inet.ts) type implementation as an example, and the [pg_catalog index](https://github.com/oguimbal/pg-mem/blob/master/src/schema/pg-catalog/index.ts) where supported types are registered)
|
|
160
|
+
|
|
161
|
+
## Extensions
|
|
162
|
+
|
|
163
|
+
No native extension is implemented (pull requests are welcome), but you can define kind-of extensions like this:
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
db.registerExtension("my-ext", (schema) => {
|
|
167
|
+
// install your ext in 'schema'
|
|
168
|
+
// ex: schema.registerFunction(...)
|
|
169
|
+
});
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Statements like `create extension "my-ext"` will then be supported.
|
|
173
|
+
|
|
174
|
+
# 📃 Libraries adapters
|
|
175
|
+
|
|
176
|
+
pg-mem provides handy shortcuts to create instances of popular libraries that will be bound to pg-mem instead of a real postgres db.
|
|
177
|
+
|
|
178
|
+
- pg-native
|
|
179
|
+
- node-postgres (pg)
|
|
180
|
+
- pg-promise (pgp)
|
|
181
|
+
- slonik
|
|
182
|
+
- typeorm
|
|
183
|
+
- knex
|
|
184
|
+
- kysely
|
|
185
|
+
- mikro-orm
|
|
186
|
+
|
|
187
|
+
[See the wiki for more details](https://github.com/oguimbal/pg-mem/wiki/Libraries-adapters)
|
|
188
|
+
|
|
189
|
+
# 💥 Inspection
|
|
190
|
+
|
|
191
|
+
## Intercept queries
|
|
192
|
+
|
|
193
|
+
If you would like to hook your database, and return ad-hoc results, you can do so like this:
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
const db = newDb();
|
|
197
|
+
|
|
198
|
+
db.public.interceptQueries((sql) => {
|
|
199
|
+
if (sql === "select * from whatever") {
|
|
200
|
+
// intercept this statement, and return something custom:
|
|
201
|
+
return [{ something: 42 }];
|
|
202
|
+
}
|
|
203
|
+
// proceed to actual SQL execution for other requests.
|
|
204
|
+
return null;
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Inspect a table
|
|
209
|
+
|
|
210
|
+
You can manually inspect a table content using the `find()` method:
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
for (const item of db.public.getTable<TItem>("mytable").find(itemTemplate)) {
|
|
214
|
+
console.log(item);
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Manually insert items
|
|
219
|
+
|
|
220
|
+
If you'd like to insert items manually into a table, you can do this like that:
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
db.public.getTable<TItem>('mytable').insert({ /* item to insert */ }))
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Subscribe to events
|
|
227
|
+
|
|
228
|
+
You can subscribe to some events, like:
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
const db = newDb();
|
|
232
|
+
|
|
233
|
+
// called on each successful sql request
|
|
234
|
+
db.on("query", (sql) => {});
|
|
235
|
+
// called on each failed sql request
|
|
236
|
+
db.on("query-failed", (sql) => {});
|
|
237
|
+
// called on schema changes
|
|
238
|
+
db.on("schema-change", () => {});
|
|
239
|
+
// called when a CREATE EXTENSION schema is encountered.
|
|
240
|
+
db.on("create-extension", (ext) => {});
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Experimental events
|
|
244
|
+
|
|
245
|
+
`pg-mem` implements a basic support for indices.
|
|
246
|
+
|
|
247
|
+
These handlers are called when a request cannot be optimized using one of the created indices.
|
|
248
|
+
|
|
249
|
+
However, a real postgres instance will be much smarter to optimize its requests... so when `pg-mem` says "this request does not use an index", dont take my word for it.
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
// called when a table is iterated entirely (ex: 'select * from data where notIndex=3' triggers it)
|
|
253
|
+
db.on('seq-scan', () => {});
|
|
254
|
+
|
|
255
|
+
// same, but on a specific table
|
|
256
|
+
db.getTable('myTable').on('seq-scan', () = {});
|
|
257
|
+
|
|
258
|
+
// will be called if pg-mem did not find any way to optimize a join
|
|
259
|
+
// (which leads to a O(n*m) lookup with the current implementation)
|
|
260
|
+
db.on('catastrophic-join-optimization', () => {});
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
# 🙋♂️ FAQ
|
|
264
|
+
|
|
265
|
+
- [Why this instead of Docker ?](https://github.com/oguimbal/pg-mem/wiki/FAQ#-why-use-pg-mem-instead-of-an-instance-of-postgres-in-docker-) _TLDR : It's faster. Docker is overkill._
|
|
266
|
+
- [What if I need an extension like uuid-ossp ?](https://github.com/oguimbal/pg-mem/wiki/FAQ#-what-if-i-need-an-extension-like-uuid-ossp-) _TLDR: You can mock those_
|
|
267
|
+
- [How to import my production schema in pg-mem ?](https://github.com/oguimbal/pg-mem/wiki/FAQ#-how-to-import-my-production-schema-in-pg-mem-) _TLDR: pg_dump with the right args_
|
|
268
|
+
- [Does pg-mem supports sql migrations ?](https://github.com/oguimbal/pg-mem/wiki/FAQ#-does-pg-mem-support-sql-migrations-scripts-) _TLDR: yes._
|
|
269
|
+
- [Does pg-mem supports plpgsql/other scripts/"create functions"/"do statements" ?](https://github.com/oguimbal/pg-mem/wiki/FAQ#-how-to-use-plpgsql-or-other-scripts-) _TLDR: kind of..._
|
|
270
|
+
|
|
271
|
+
Detailed answers [in the wiki](https://github.com/oguimbal/pg-mem/wiki/FAQ)
|
|
272
|
+
|
|
273
|
+
# ⚠️ Current limitations
|
|
274
|
+
|
|
275
|
+
- Materialized views are implemented as views (meaning that they are always up-to-date, without needing them to refresh)
|
|
276
|
+
- Indices implementations are basic
|
|
277
|
+
- No support for timezones
|
|
278
|
+
- All number-like types are all handled as javascript numbers, meaning that types like `numeric(x,y)` could not behave as expected.
|
|
279
|
+
|
|
280
|
+
# 🐜 Development
|
|
281
|
+
|
|
282
|
+
Pull requests are welcome :)
|
|
283
|
+
|
|
284
|
+
Unit tests are ran using [Bun](https://bun.sh/), which you will have to install to run tests.
|
|
285
|
+
|
|
286
|
+
## Run all tests
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
bun test
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## Debug a test
|
|
293
|
+
|
|
294
|
+
Using vscode:
|
|
295
|
+
|
|
296
|
+
1. Add a `.only` on the test you'd like to debug
|
|
297
|
+
2. Just hit F5 (or execute via the debugger tab), which should launch your test with debugger attached
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { LibAdapters, SlonikAdapterOptions, BindServerOptions, BindServerResult } from '../interfaces';
|
|
2
|
+
import { _IDb } from '../interfaces-private';
|
|
3
|
+
export declare function replaceQueryArgs$(this: void, sql: string, values: any[]): string;
|
|
4
|
+
export declare class Adapters implements LibAdapters {
|
|
5
|
+
private db;
|
|
6
|
+
private _mikroPatched?;
|
|
7
|
+
constructor(db: _IDb);
|
|
8
|
+
createPg(queryLatency?: number): {
|
|
9
|
+
Pool: any;
|
|
10
|
+
Client: any;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use `createTypeormDataSource` instead.
|
|
14
|
+
*/
|
|
15
|
+
createTypeormConnection(postgresOptions: any, queryLatency?: number): any;
|
|
16
|
+
createTypeormDataSource(postgresOptions: any, queryLatency?: number): any;
|
|
17
|
+
createSlonik(opts?: SlonikAdapterOptions): any;
|
|
18
|
+
createPgPromise(queryLatency?: number): any;
|
|
19
|
+
createPgNative(queryLatency?: number): {
|
|
20
|
+
new (): {
|
|
21
|
+
connect(a: any, b: any): Promise<void>;
|
|
22
|
+
connectSync(): void;
|
|
23
|
+
prepare(name: string, sql: string, npar: number, callback: any): Promise<void>;
|
|
24
|
+
prepareSync(name: string, sql: string, npar: number): void;
|
|
25
|
+
execute(name: string, a: any, b: any): Promise<void>;
|
|
26
|
+
executeSync(name: string, pars?: any): any[];
|
|
27
|
+
query(sql: string, b: any, c: any): Promise<void>;
|
|
28
|
+
querySync(sql: string, params: any[]): any[];
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
createKnex(queryLatency?: number, knexConfig?: object): any;
|
|
32
|
+
createKysely(queryLatency?: number, kyselyConfig?: object): any;
|
|
33
|
+
createMikroOrm(mikroOrmOptions: any, queryLatency?: number): Promise<any>;
|
|
34
|
+
createPostgresJsTag(queryLatency?: number): any;
|
|
35
|
+
bindServer(opts?: BindServerOptions): Promise<BindServerResult>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=adapters.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { _ISchema } from '../interfaces-private';
|
|
2
|
+
export declare const socketAdapter: import("../utils").LazySync<(mem: _ISchema, queryLatency?: number) => {
|
|
3
|
+
readonly peer: any;
|
|
4
|
+
isTop: boolean;
|
|
5
|
+
setNoDelay(): void;
|
|
6
|
+
write(data: any, mcb1?: any, mcb2?: any): boolean;
|
|
7
|
+
end(): any;
|
|
8
|
+
destroySoon(): void;
|
|
9
|
+
connect(): any;
|
|
10
|
+
pause(): any;
|
|
11
|
+
resume(): any;
|
|
12
|
+
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: any[]): void;
|
|
13
|
+
addListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
14
|
+
on<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
15
|
+
once<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
16
|
+
removeListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
17
|
+
off<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
18
|
+
removeAllListeners(event?: string | symbol | undefined): any;
|
|
19
|
+
setMaxListeners(n: number): any;
|
|
20
|
+
getMaxListeners(): number;
|
|
21
|
+
listeners<K>(eventName: string | symbol): Function[];
|
|
22
|
+
rawListeners<K>(eventName: string | symbol): Function[];
|
|
23
|
+
emit<K>(eventName: string | symbol, ...args: any[]): boolean;
|
|
24
|
+
listenerCount<K>(eventName: string | symbol, listener?: Function | undefined): number;
|
|
25
|
+
prependListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
26
|
+
prependOnceListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
27
|
+
eventNames(): (string | symbol)[];
|
|
28
|
+
}>;
|
|
29
|
+
export declare function bindPgServer(this: void, peer: any, mem: _ISchema, queryLatency?: number): void;
|
|
30
|
+
//# sourceMappingURL=pg-socket-adapter.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { _Column, IValue, _Transaction, SchemaField, nil, ISubscription, DropHandler } from './interfaces-private';
|
|
2
|
+
import type { MemoryTable } from './table';
|
|
3
|
+
import { Evaluator } from './evaluator';
|
|
4
|
+
import { ColumnConstraint, AlterColumn } from 'pgsql-ast-parser';
|
|
5
|
+
import { BIndex } from './schema/btree-index';
|
|
6
|
+
export declare class ColRef implements _Column {
|
|
7
|
+
readonly table: MemoryTable;
|
|
8
|
+
expression: Evaluator;
|
|
9
|
+
name: string;
|
|
10
|
+
comment: string | nil;
|
|
11
|
+
default: IValue | nil;
|
|
12
|
+
notNull: boolean;
|
|
13
|
+
generated: boolean;
|
|
14
|
+
usedInIndexes: Set<BIndex>;
|
|
15
|
+
private drophandlers;
|
|
16
|
+
constructor(table: MemoryTable, expression: Evaluator, _schema: SchemaField, name: string);
|
|
17
|
+
addConstraints(clist: ColumnConstraint[], t: _Transaction): this;
|
|
18
|
+
private addNotNullConstraint;
|
|
19
|
+
rename(to: string, t: _Transaction): this;
|
|
20
|
+
alter(alter: AlterColumn, t: _Transaction): this;
|
|
21
|
+
private replaceExpression;
|
|
22
|
+
drop(t: _Transaction): void;
|
|
23
|
+
checkConstraints(toInsert: any, t: _Transaction): void;
|
|
24
|
+
setDefaults(toInsert: any, t: _Transaction): void;
|
|
25
|
+
onDrop(sub: DropHandler): ISubscription;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=column.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TableConstraintForeignKey } from 'pgsql-ast-parser';
|
|
2
|
+
import { _IConstraint, _ITable, _Transaction } from '../interfaces-private';
|
|
3
|
+
export declare class ForeignKey implements _IConstraint {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
private unsubs;
|
|
6
|
+
private table;
|
|
7
|
+
private foreignTable;
|
|
8
|
+
get db(): import("../interfaces-private")._IDb;
|
|
9
|
+
get schema(): import("../interfaces-private")._ISchema;
|
|
10
|
+
constructor(name: string);
|
|
11
|
+
install(_t: _Transaction, cst: TableConstraintForeignKey, table: _ITable): this;
|
|
12
|
+
uninstall(t: _Transaction): void;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=foreign-key.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AlterColumnAddGenerated, Expr, nil } from 'pgsql-ast-parser';
|
|
2
|
+
import { _Column, _IConstraint, _Transaction } from '../interfaces-private';
|
|
3
|
+
export declare class GeneratedComputedConstraint implements _IConstraint {
|
|
4
|
+
readonly name: string | nil;
|
|
5
|
+
private column;
|
|
6
|
+
private expression;
|
|
7
|
+
private subs;
|
|
8
|
+
private get table();
|
|
9
|
+
private get schema();
|
|
10
|
+
constructor(name: string | nil, column: _Column, expression: Expr);
|
|
11
|
+
uninstall(t: _Transaction): void;
|
|
12
|
+
install(ct: _Transaction, _c: AlterColumnAddGenerated): void;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=generated-from-expr.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AlterColumnAddGenerated, nil } from 'pgsql-ast-parser';
|
|
2
|
+
import { _Column, _IConstraint, _Transaction } from '../interfaces-private';
|
|
3
|
+
export declare class GeneratedIdentityConstraint implements _IConstraint {
|
|
4
|
+
readonly name: string | nil;
|
|
5
|
+
private column;
|
|
6
|
+
private subs;
|
|
7
|
+
private get table();
|
|
8
|
+
private get schema();
|
|
9
|
+
constructor(name: string | nil, column: _Column);
|
|
10
|
+
uninstall(t: _Transaction): void;
|
|
11
|
+
install(ct: _Transaction, _c: AlterColumnAddGenerated): void;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=generated-identity.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { _IConstraint, _IIndex, _ITable, _Transaction } from '../interfaces-private';
|
|
2
|
+
export declare class IndexConstraint implements _IConstraint {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly index: _IIndex;
|
|
5
|
+
private table;
|
|
6
|
+
constructor(name: string, index: _IIndex, table: _ITable);
|
|
7
|
+
uninstall(t: _Transaction): void;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=index-cst.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { _IConstraint, _Transaction } from '../interfaces-private';
|
|
2
|
+
export declare class SubscriptionConstraint implements _IConstraint {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly uninstall: (t: _Transaction) => void;
|
|
5
|
+
constructor(name: string, uninstall: (t: _Transaction) => void);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=subscription.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { _IConstraint, _Transaction } from '../interfaces-private';
|
|
2
|
+
export declare class ConstraintWrapper implements _IConstraint {
|
|
3
|
+
private refs;
|
|
4
|
+
private inner;
|
|
5
|
+
constructor(refs: Map<string, _IConstraint>, inner: _IConstraint);
|
|
6
|
+
get name(): string | import("../interfaces").nil;
|
|
7
|
+
uninstall(t: _Transaction): void;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=wrapped.d.ts.map
|