@malloydata/db-postgres 0.0.240-dev250311202829 → 0.0.240-dev250311214430
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/package.json +2 -2
- package/dist/postgres.spec.d.ts +0 -1
- package/dist/postgres.spec.js +0 -138
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/db-postgres",
|
|
3
|
-
"version": "0.0.240-
|
|
3
|
+
"version": "0.0.240-dev250311214430",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"prepublishOnly": "npm run build"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@malloydata/malloy": "^0.0.240-
|
|
25
|
+
"@malloydata/malloy": "^0.0.240-dev250311214430",
|
|
26
26
|
"@types/pg": "^8.6.1",
|
|
27
27
|
"pg": "^8.7.1",
|
|
28
28
|
"pg-query-stream": "4.2.3"
|
package/dist/postgres.spec.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/postgres.spec.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright 2023 Google LLC
|
|
4
|
-
*
|
|
5
|
-
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
-
* a copy of this software and associated documentation files
|
|
7
|
-
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
-
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
-
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
-
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
-
* subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be
|
|
14
|
-
* included in all copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
-
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
-
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
-
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
-
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
const postgres_connection_1 = require("./postgres_connection");
|
|
26
|
-
const test_1 = require("@malloydata/malloy/test");
|
|
27
|
-
const [describe] = (0, test_1.describeIfDatabaseAvailable)(['postgres']);
|
|
28
|
-
/*
|
|
29
|
-
* !IMPORTANT
|
|
30
|
-
*
|
|
31
|
-
* The connection is reused for each test, so if you do not name your tables
|
|
32
|
-
* and keys uniquely for each test you will see cross test interactions.
|
|
33
|
-
*/
|
|
34
|
-
describe('PostgresConnection', () => {
|
|
35
|
-
let connection;
|
|
36
|
-
let getTableSchema;
|
|
37
|
-
let getSQLBlockSchema;
|
|
38
|
-
beforeAll(async () => {
|
|
39
|
-
connection = new postgres_connection_1.PostgresConnection('duckdb');
|
|
40
|
-
await connection.runSQL('SELECT 1');
|
|
41
|
-
});
|
|
42
|
-
afterAll(async () => {
|
|
43
|
-
await connection.close();
|
|
44
|
-
});
|
|
45
|
-
beforeEach(async () => {
|
|
46
|
-
getTableSchema = jest
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
-
.spyOn(postgres_connection_1.PostgresConnection.prototype, 'fetchTableSchema')
|
|
49
|
-
.mockResolvedValue({
|
|
50
|
-
type: 'table',
|
|
51
|
-
dialect: 'postgres',
|
|
52
|
-
name: 'name',
|
|
53
|
-
tablePath: 'test',
|
|
54
|
-
connection: 'postgres',
|
|
55
|
-
});
|
|
56
|
-
getSQLBlockSchema = jest
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
|
-
.spyOn(postgres_connection_1.PostgresConnection.prototype, 'fetchSelectSchema')
|
|
59
|
-
.mockResolvedValue({
|
|
60
|
-
type: 'sql select',
|
|
61
|
-
dialect: 'postgres',
|
|
62
|
-
name: 'name',
|
|
63
|
-
selectStr: SQL_BLOCK_1.selectStr,
|
|
64
|
-
connection: 'postgres',
|
|
65
|
-
fields: [],
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
afterEach(() => {
|
|
69
|
-
jest.resetAllMocks();
|
|
70
|
-
});
|
|
71
|
-
it('caches table schema', async () => {
|
|
72
|
-
await connection.fetchSchemaForTables({ 'test1': 'table1' }, {});
|
|
73
|
-
expect(getTableSchema).toBeCalledTimes(1);
|
|
74
|
-
await connection.fetchSchemaForTables({ 'test1': 'table1' }, {});
|
|
75
|
-
expect(getTableSchema).toBeCalledTimes(1);
|
|
76
|
-
});
|
|
77
|
-
it('refreshes table schema', async () => {
|
|
78
|
-
await connection.fetchSchemaForTables({ 'test2': 'table2' }, {});
|
|
79
|
-
expect(getTableSchema).toBeCalledTimes(1);
|
|
80
|
-
await connection.fetchSchemaForTables({ 'test2': 'table2' }, { refreshTimestamp: Date.now() + 10 });
|
|
81
|
-
expect(getTableSchema).toBeCalledTimes(2);
|
|
82
|
-
});
|
|
83
|
-
it('caches sql schema', async () => {
|
|
84
|
-
await connection.fetchSchemaForSQLStruct(SQL_BLOCK_1, {});
|
|
85
|
-
expect(getSQLBlockSchema).toBeCalledTimes(1);
|
|
86
|
-
await connection.fetchSchemaForSQLStruct(SQL_BLOCK_1, {});
|
|
87
|
-
expect(getSQLBlockSchema).toBeCalledTimes(1);
|
|
88
|
-
});
|
|
89
|
-
it('refreshes sql schema', async () => {
|
|
90
|
-
await connection.fetchSchemaForSQLStruct(SQL_BLOCK_2, {});
|
|
91
|
-
expect(getSQLBlockSchema).toBeCalledTimes(1);
|
|
92
|
-
await connection.fetchSchemaForSQLStruct(SQL_BLOCK_2, {
|
|
93
|
-
refreshTimestamp: Date.now() + 10,
|
|
94
|
-
});
|
|
95
|
-
expect(getSQLBlockSchema).toBeCalledTimes(2);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
const SQL_BLOCK_1 = {
|
|
99
|
-
type: 'sql_select',
|
|
100
|
-
name: 'block1',
|
|
101
|
-
dialect: 'postgres',
|
|
102
|
-
connection: 'postgres',
|
|
103
|
-
fields: [],
|
|
104
|
-
selectStr: `
|
|
105
|
-
SELECT
|
|
106
|
-
created_at,
|
|
107
|
-
sale_price,
|
|
108
|
-
inventory_item_id
|
|
109
|
-
FROM 'order_items.parquet'
|
|
110
|
-
SELECT
|
|
111
|
-
id,
|
|
112
|
-
product_department,
|
|
113
|
-
product_category,
|
|
114
|
-
created_at AS inventory_items_created_at
|
|
115
|
-
FROM "inventory_items.parquet"
|
|
116
|
-
`,
|
|
117
|
-
};
|
|
118
|
-
const SQL_BLOCK_2 = {
|
|
119
|
-
type: 'sql_select',
|
|
120
|
-
name: 'block2',
|
|
121
|
-
dialect: 'postgres',
|
|
122
|
-
connection: 'postgres',
|
|
123
|
-
fields: [],
|
|
124
|
-
selectStr: `
|
|
125
|
-
SELECT
|
|
126
|
-
created_at,
|
|
127
|
-
sale_price,
|
|
128
|
-
inventory_item_id
|
|
129
|
-
FROM read_parquet('order_items2.parquet', arg='value')
|
|
130
|
-
SELECT
|
|
131
|
-
id,
|
|
132
|
-
product_department,
|
|
133
|
-
product_category,
|
|
134
|
-
created_at AS inventory_items_created_at
|
|
135
|
-
FROM read_parquet("inventory_items2.parquet")
|
|
136
|
-
`,
|
|
137
|
-
};
|
|
138
|
-
//# sourceMappingURL=postgres.spec.js.map
|