Skip to content

Commit bca5d95

Browse files
committed
experiment: postgres from browser
1 parent 44c214a commit bca5d95

File tree

5 files changed

+230
-5
lines changed

5 files changed

+230
-5
lines changed

js/packages/quary-extension/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,16 @@
209209
"crypto-browserify": "^3.12.0",
210210
"file-loader": "^6.2.0",
211211
"lodash": "^4.17.21",
212+
"node-polyfill-webpack-plugin": "^4.0.0",
212213
"papaparse": "^5.4.1",
214+
"postgres": "^3.4.4",
213215
"quary-extension-ui": "workspace:*",
214216
"raw-loader": "^4.0.2",
215217
"sql.js": "1.10.3",
216218
"stream-browserify": "^3.0.0",
217219
"url-loader": "^4.1.1",
218220
"vm-browserify": "^1.1.2",
221+
"webpack-node-externals": "^3.0.0",
219222
"zod": "^3.23.8"
220223
}
221224
}

js/packages/quary-extension/src/web/createDatabaseFromConfig.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from './servicesDatabaseDuckDBNode'
1919
import { ServicesDatabaseRedshiftNode } from './servicesDatabaseRedshiftNode'
2020
import { ServicesDatabasePostgresNode } from './servicesDatabasePostgresNode'
21+
import { ServicesDatabasePostgres } from './servicesDatabasePostgres'
2122

2223
/**
2324
* Creates a database instance from a given configuration.
@@ -156,10 +157,9 @@ export const databaseFromConfig = async (
156157
case 'postgres': {
157158
switch (vscode.env.uiKind) {
158159
case vscode.UIKind.Web: {
159-
return Err({
160-
code: ErrorCodes.INVALID_ARGUMENT,
161-
message: 'Postgres is not supported in the web extension',
162-
})
160+
const postgres = new ServicesDatabasePostgres()
161+
// @ts-ignore
162+
return Ok(postgres)
163163
}
164164
case vscode.UIKind.Desktop: {
165165
const { schema } = config.config.postgres
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Ok } from '@shared/result'
2+
import * as postgres from 'postgres'
3+
import { ServicesDatabase } from './servicesDatabase'
4+
5+
const DefaultDatabaseDependentSettings = {
6+
runQueriesByDefault: false,
7+
lookForCacheViews: false,
8+
}
9+
10+
// @ts-ignore
11+
export class ServicesDatabasePostgres implements ServicesDatabase {
12+
readonly db: any
13+
14+
// @ts-ignore
15+
async runStatement(statement: string): Promise<Result<QueryResult>> {
16+
const results = this.db`
17+
${statement}
18+
`
19+
console.log(results)
20+
throw new Error('Not implemented')
21+
}
22+
23+
constructor() {
24+
this.db = postgres({
25+
port: 5432,
26+
host: 'localhost',
27+
database: 'postgres',
28+
username: 'postgres',
29+
password: 'mysecretpassword',
30+
})
31+
}
32+
33+
async listTables() {
34+
return Ok([])
35+
}
36+
}

js/packages/quary-extension/webpack.web.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ module.exports = (
8080
},
8181

8282
plugins: [
83+
new webpack.NormalModuleReplacementPlugin(
84+
/^net$/,
85+
'net-browserify'
86+
),
8387
new webpack.optimize.LimitChunkCountPlugin({
8488
maxChunks: 1, // disable chunks by default since web extensions must be a single bundle
8589
}),
@@ -94,7 +98,7 @@ module.exports = (
9498
__PACKAGE_VERSION__: JSON.stringify(packageJson.version),
9599
}),
96100
],
97-
externals: {
101+
externals: {
98102
vscode: 'commonjs vscode', // ignored because it doesn't exist
99103
},
100104
performance: {

0 commit comments

Comments
 (0)