Skip to content

Commit

Permalink
experiment: postgres from browser
Browse files Browse the repository at this point in the history
  • Loading branch information
benfdking committed May 24, 2024
1 parent 44c214a commit bca5d95
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 5 deletions.
3 changes: 3 additions & 0 deletions js/packages/quary-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,16 @@
"crypto-browserify": "^3.12.0",
"file-loader": "^6.2.0",
"lodash": "^4.17.21",
"node-polyfill-webpack-plugin": "^4.0.0",
"papaparse": "^5.4.1",
"postgres": "^3.4.4",
"quary-extension-ui": "workspace:*",
"raw-loader": "^4.0.2",
"sql.js": "1.10.3",
"stream-browserify": "^3.0.0",
"url-loader": "^4.1.1",
"vm-browserify": "^1.1.2",
"webpack-node-externals": "^3.0.0",
"zod": "^3.23.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from './servicesDatabaseDuckDBNode'
import { ServicesDatabaseRedshiftNode } from './servicesDatabaseRedshiftNode'
import { ServicesDatabasePostgresNode } from './servicesDatabasePostgresNode'
import { ServicesDatabasePostgres } from './servicesDatabasePostgres'

/**
* Creates a database instance from a given configuration.
Expand Down Expand Up @@ -156,10 +157,9 @@ export const databaseFromConfig = async (
case 'postgres': {
switch (vscode.env.uiKind) {
case vscode.UIKind.Web: {
return Err({
code: ErrorCodes.INVALID_ARGUMENT,
message: 'Postgres is not supported in the web extension',
})
const postgres = new ServicesDatabasePostgres()
// @ts-ignore
return Ok(postgres)
}
case vscode.UIKind.Desktop: {
const { schema } = config.config.postgres
Expand Down
36 changes: 36 additions & 0 deletions js/packages/quary-extension/src/web/servicesDatabasePostgres.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Ok } from '@shared/result'
import * as postgres from 'postgres'
import { ServicesDatabase } from './servicesDatabase'

const DefaultDatabaseDependentSettings = {
runQueriesByDefault: false,
lookForCacheViews: false,
}

// @ts-ignore
export class ServicesDatabasePostgres implements ServicesDatabase {
readonly db: any

// @ts-ignore
async runStatement(statement: string): Promise<Result<QueryResult>> {
const results = this.db`
${statement}
`
console.log(results)
throw new Error('Not implemented')
}

constructor() {
this.db = postgres({
port: 5432,
host: 'localhost',
database: 'postgres',
username: 'postgres',
password: 'mysecretpassword',
})
}

async listTables() {
return Ok([])
}
}
6 changes: 5 additions & 1 deletion js/packages/quary-extension/webpack.web.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ module.exports = (
},

plugins: [
new webpack.NormalModuleReplacementPlugin(
/^net$/,
'net-browserify'
),
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1, // disable chunks by default since web extensions must be a single bundle
}),
Expand All @@ -94,7 +98,7 @@ module.exports = (
__PACKAGE_VERSION__: JSON.stringify(packageJson.version),
}),
],
externals: {
externals: {
vscode: 'commonjs vscode', // ignored because it doesn't exist
},
performance: {
Expand Down
Loading

0 comments on commit bca5d95

Please # to comment.