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

chore(driver-adapters): remove external wasm deps hack for napi, lift driver-adapters from query-engine/.. to libs/.. #5115

Merged
merged 21 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4e19353
feat(schema-engine-wasm): created wasm-compatible schema-engine-wasm …
jkomyno Jan 9, 2025
f1cb86f
chore(schema-engine-wasm): added "make build-se-wasm" command
jkomyno Jan 9, 2025
a339bb5
fix(schema-engine-wasm): replace "SchemaEngineParams" class instance …
jkomyno Jan 9, 2025
30e488a
feat(schema-engine-wasm): implement playground skeleton
jkomyno Jan 9, 2025
93379e7
fix(schema-engine-wasm): clippy
jkomyno Jan 10, 2025
4fdd27b
chore(schema-engine-wasm): lift "driver-adapters" from "query-engine"…
jkomyno Jan 10, 2025
0360567
Delete libs/driver-adapters/executor/bench/seed.sql.gz
jkomyno Jan 10, 2025
d492067
chore: update Cargo.lock
jkomyno Jan 10, 2025
69de78e
Merge branch 'feat/schema-engine-wasm-init' into chore/lift-driver-ad…
jkomyno Jan 10, 2025
3ed63a5
chore: update driver-adapters path references
jkomyno Jan 10, 2025
26f8a0d
Merge branch 'chore/lift-driver-adapters' of github.com:prisma/prisma…
jkomyno Jan 10, 2025
e6d2fb1
chore: update query-engine-wasm path references
jkomyno Jan 10, 2025
40b522a
chore: update query-engine-wasm path references
jkomyno Jan 10, 2025
c5270b0
chore: update query-engine-wasm and schema-engine-wasm path references
jkomyno Jan 10, 2025
f7d6654
feat(driver-adapters): get rid of external import hack, fix paths in …
jkomyno Jan 10, 2025
f8c3578
Revert "Delete libs/driver-adapters/executor/bench/seed.sql.gz"
jkomyno Jan 10, 2025
a9712e1
chore: merge main, fix conflicts
jkomyno Jan 13, 2025
0fb1712
chore: fix conflicts
jkomyno Jan 13, 2025
30726a6
chore: fix pnpm version to avoid https://github.com/pnpm/pnpm/issues/…
jkomyno Jan 13, 2025
63c00b1
fix: use actual dist JS file
jkomyno Jan 14, 2025
2a2e03a
chore: update tsup to latest
jkomyno Jan 14, 2025
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
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ members = [
"query-engine/core-tests",
"query-engine/black-box-tests",
"query-engine/dmmf",
"query-engine/driver-adapters",
"query-engine/query-structure",
"query-engine/query-engine",
"query-engine/query-engine-node-api",
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ test-driver-adapter-pg: test-pg-js
test-driver-adapter-pg-wasm: test-pg-wasm

start-pg-bench:
docker compose -f query-engine/driver-adapters/executor/bench/docker-compose.yml up --wait -d --remove-orphans postgres
docker compose -f libs/driver-adapters/executor/bench/docker-compose.yml up --wait -d --remove-orphans postgres

setup-pg-bench: start-pg-bench build-qe-napi build-qe-wasm build-driver-adapters-kit

run-bench:
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/bench?schema=imdb_bench&sslmode=disable" \
node --experimental-wasm-modules query-engine/driver-adapters/executor/dist/bench.mjs
node --experimental-wasm-modules libs/driver-adapters/executor/dist/bench.mjs

bench-pg-js: setup-pg-bench run-bench

Expand Down Expand Up @@ -409,7 +409,7 @@ measure-qe-wasm: build-qe-wasm-gz
done;

build-driver-adapters-kit: build-driver-adapters
cd query-engine/driver-adapters && pnpm i && pnpm build
cd libs/driver-adapters && pnpm i && pnpm build

build-driver-adapters: ensure-prisma-present
@echo "Building driver adapters..."
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,16 @@
"pnpm": "^9.14.2"
},
"name": "executor",
"type": "module",
"version": "0.0.1",
"description": "",
"private": true,
"scripts": {
"build": "tsup ./src/testd-qe.ts ./src/bench.ts --format esm --dts",
"build": "tsup ./src/testd-qe.ts ./src/demo-se.ts ./src/bench.ts --format esm --dts",
"test:qe": "node --import tsx ./src/testd-qe.ts",
"demo:se": "node --import tsx ./src/demo-se.ts",
"clean:d1": "rm -rf ../../connector-test-kit-rs/query-engine-tests/.wrangler"
},
"tsup": {
"external": [
"../../../query-engine-wasm/pkg/postgresql/query_engine_bg.js",
"../../../query-engine-wasm/pkg/mysql/query_engine_bg.js",
"../../../query-engine-wasm/pkg/sqlite/query_engine_bg.js",
"../../../schema-engine-wasm/pkg/postgresql/schema_engine_bg.js",
"../../../schema-engine-wasm/pkg/mysql/schema_engine_bg.js",
"../../../schema-engine-wasm/pkg/sqlite/schema_engine_bg.js"
]
},
"keywords": [],
"author": "",
"sideEffects": false,
Expand Down
33 changes: 33 additions & 0 deletions libs/driver-adapters/executor/src/query-engine-wasm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import fs from 'node:fs/promises'
import path from 'node:path'
import { __dirname, normaliseProvider } from './utils'
import type { Queryable } from '@prisma/driver-adapter-utils'

const relativePath = '../../../../query-engine/query-engine-wasm/pkg'

const initializedModules = new Set<Queryable['provider']>()

export async function getQueryEngineForProvider(provider: Queryable['provider']) {
const normalisedProvider = normaliseProvider(provider)
const engine = await import(`${relativePath}/${normalisedProvider}/query_engine_bg.js`)

if (!initializedModules.has(provider)) {
const bytes = await fs.readFile(
path.resolve(
__dirname,
relativePath,
normalisedProvider,
'query_engine_bg.wasm',
),
)

const module = new WebAssembly.Module(bytes)
const instance = new WebAssembly.Instance(module, {
'./query_engine_bg.js': engine,
})
engine.__wbg_set_wasm(instance.exports)
initializedModules.add(provider)
}

return engine.QueryEngine
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
<<<<<<< HEAD:libs/driver-adapters/executor/src/schema-engine-wasm.ts
import fs from 'node:fs/promises'
import path from 'node:path'
import { __dirname, normaliseProvider } from './utils.js'
import type { Queryable } from '@prisma/driver-adapter-utils'

const relativePath = '../../../../schema-engine/schema-engine-wasm/pkg'

const initializedModules = new Set<Queryable['provider']>()

export async function getSchemaEngineForProvider(provider: Queryable['provider']) {
const normalisedProvider = normaliseProvider(provider)
const engine = await import(`${relativePath}/${normalisedProvider}/schema_engine_bg.js`)

if (!initializedModules.has(provider)) {
const bytes = await fs.readFile(
path.resolve(
__dirname,
relativePath,
normalisedProvider,
'schema_engine_bg.wasm',
),
)

=======
jkomyno marked this conversation as resolved.
Show resolved Hide resolved
import * as wasmPostgres from '../../../../schema-engine/schema-engine-wasm/pkg/postgresql/schema_engine_bg.js'
import * as wasmMysql from '../../../../schema-engine/schema-engine-wasm/pkg/mysql/schema_engine_bg.js'
import * as wasmSqlite from '../../../../schema-engine/schema-engine-wasm/pkg/sqlite/schema_engine_bg.js'
Expand All @@ -20,6 +45,7 @@ export async function getSchemaEngineForProvider(provider: EngineName) {
if (!initializedModules.has(provider)) {
const subDir = provider === 'postgres' ? 'postgresql' : provider
const bytes = await fs.readFile(path.resolve(__dirname, '..', '..', '..', '..', 'schema-engine', 'schema-engine-wasm', 'pkg', subDir, 'schema_engine_bg.wasm'))
>>>>>>> main:query-engine/driver-adapters/executor/src/schema-engine-wasm.ts
const module = new WebAssembly.Module(bytes)
const instance = new WebAssembly.Instance(module, { './schema_engine_bg.js': engine })
engine.__wbg_set_wasm(instance.exports)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { D1Database, D1PreparedStatement, D1Result } from '@cloudflare/workers-types'
import type { Queryable } from '@prisma/driver-adapter-utils'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

Expand All @@ -11,6 +12,10 @@ export function copyPathName({ fromURL, toURL }: { fromURL: string; toURL: strin
return toObj.toString()
}

export function normaliseProvider(provider: Queryable['provider']) {
return provider === 'postgres' ? 'postgresql' : provider
}

export function postgresSchemaName(url: string) {
return new URL(url).searchParams.get('schema') ?? undefined
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"build:prisma": "pnpm -r --parallel dev",
"build:executor": "pnpm -r --filter executor build",
"lint": "pnpm -r run lint",
"clean": "git clean -dXf -e !query-engine/driver-adapters"
"clean": "git clean -dXf -e !libs/driver-adapters"
},
"keywords": [],
"author": "",
Expand Down
2 changes: 1 addition & 1 deletion query-engine/connector-test-kit-rs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ To run tests through a driver adapters, you should also configure the following
Example:

```shell
export EXTERNAL_TEST_EXECUTOR="$WORKSPACE_ROOT/query-engine/driver-adapters/executor/script/testd-qe.sh"
export EXTERNAL_TEST_EXECUTOR="$WORKSPACE_ROOT/libs/driver-adapters/executor/script/testd-qe.sh"
export DRIVER_ADAPTER=neon
export ENGINE=wasm
export DRIVER_ADAPTER_CONFIG ='{ "proxyUrl": "127.0.0.1:5488/v1" }'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ impl TestConfig {
}

pub fn external_test_executor_path(&self) -> Option<String> {
const DEFAULT_TEST_EXECUTOR: &str = "query-engine/driver-adapters/executor/script/testd-qe.sh";
const DEFAULT_TEST_EXECUTOR: &str = "libs/driver-adapters/executor/script/testd-qe.sh";
self.with_driver_adapter()
.and_then(|_| {
Self::workspace_root().or_else(|| {
Expand Down
43 changes: 0 additions & 43 deletions query-engine/driver-adapters/executor/src/query-engine-wasm.ts

This file was deleted.

2 changes: 1 addition & 1 deletion query-engine/query-engine-node-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ sql-connector = { path = "../connectors/sql-query-connector", package = "sql-que
"all-native",
] }
query-structure = { path = "../query-structure" }
driver-adapters = { path = "../driver-adapters", features = [
driver-adapters = { path = "../../libs/driver-adapters", features = [
"postgresql",
"sqlite",
"mysql",
Expand Down
2 changes: 1 addition & 1 deletion query-engine/query-engine-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ request-handlers = { path = "../request-handlers", default-features = false, fea
"driver-adapters",
] }
query-core = { path = "../core" }
driver-adapters = { path = "../driver-adapters" }
driver-adapters = { path = "../../libs/driver-adapters" }
telemetry = { path = "../../libs/telemetry" }
quaint.workspace = true
connection-string.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
{
"groupName": "Driver Adapters directory",
"matchFileNames": [
"query-engine/driver-adapters/**"
"libs/driver-adapters/**"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion schema-engine/schema-engine-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tsify.workspace = true
wasm-bindgen.workspace = true
wasm-bindgen-futures.workspace = true
wasm-rs-dbg.workspace = true
driver-adapters = { path = "../../query-engine/driver-adapters" }
driver-adapters = { path = "../../libs/driver-adapters" }

[build-dependencies]
build-utils.path = "../../libs/build-utils"
Expand Down
Loading