Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experiment: postgres from browser #296

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions js/packages/quary-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,20 @@
"crypto-browserify": "^3.12.0",
"file-loader": "^6.2.0",
"lodash": "^4.17.21",
"net-browserify": "^0.2.4",
"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",
"stream-http": "^3.2.0",
"timers-browserify": "^2.0.12",
"tls-browserify": "^0.2.2",
"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 @@ -19,6 +19,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 @@ -176,10 +177,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
2 changes: 2 additions & 0 deletions js/packages/quary-extension/src/web/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async function activateCommands(
)
}


const SENTRY_DSN =
'https://360983d50cb2c46d0d39778ce2a3443e@o4506173297524736.ingest.sentry.io/4506175684673536'
const JUNE_ANALYTICS = '9PbCtSiPLLggvaE5'
Expand All @@ -43,6 +44,7 @@ export async function activate(context: vscode.ExtensionContext) {
const hostDetails = await VSCodeInstanceContext.getHostDetails()
const isProduction = hostDetails.environment === 'production'


console.info(`starting extension activation with details: ${hostDetails}`)

const logger = isProduction
Expand Down
78 changes: 78 additions & 0 deletions js/packages/quary-extension/src/web/postgres/bytes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const size = 256
let buffer = Buffer.allocUnsafe(size)

const messages = 'BCcDdEFfHPpQSX'.split('').reduce((acc, x) => {
const v = x.charCodeAt(0)
acc[x] = () => {
buffer[0] = v
b.i = 5
return b
}
return acc
}, {})

const b = Object.assign(reset, messages, {
N: String.fromCharCode(0),
i: 0,
inc(x) {
b.i += x
return b
},
str(x) {
const length = Buffer.byteLength(x)
fit(length)
b.i += buffer.write(x, b.i, length, 'utf8')
return b
},
i16(x) {
fit(2)
buffer.writeUInt16BE(x, b.i)
b.i += 2
return b
},
i32(x, i) {
if (i || i === 0) {
buffer.writeUInt32BE(x, i)
return b
}
fit(4)
buffer.writeUInt32BE(x, b.i)
b.i += 4
return b
},
z(x) {
fit(x)
buffer.fill(0, b.i, b.i + x)
b.i += x
return b
},
raw(x) {
buffer = Buffer.concat([buffer.subarray(0, b.i), x])
b.i = buffer.length
return b
},
end(at = 1) {
buffer.writeUInt32BE(b.i - at, at)
const out = buffer.subarray(0, b.i)
b.i = 0
buffer = Buffer.allocUnsafe(size)
return out
}
})

export default b

function fit(x) {
if (buffer.length - b.i < x) {
const prev = buffer
, length = prev.length

buffer = Buffer.allocUnsafe(length + (length >> 1) + x)
prev.copy(buffer)
}
}

function reset() {
b.i = 0
return b
}
Loading