Skip to content

Commit

Permalink
feat(driver-adapters): get rid of external import hack, fix paths in …
Browse files Browse the repository at this point in the history
…Napi engine scenario
  • Loading branch information
jkomyno committed Jan 10, 2025
1 parent c5270b0 commit 737b8b6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 34 deletions.
11 changes: 1 addition & 10 deletions libs/driver-adapters/executor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"pnpm": "^9.14.2"
},
"name": "executor",
"type": "module",
"version": "0.0.1",
"description": "",
"private": true,
Expand All @@ -13,16 +14,6 @@
"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/query-engine-wasm/pkg/postgresql/query_engine_bg.js",
"../../../query-engine/query-engine-wasm/pkg/mysql/query_engine_bg.js",
"../../../query-engine/query-engine-wasm/pkg/sqlite/query_engine_bg.js",
"../../../schema-engine/schema-engine-wasm/pkg/postgresql/schema_engine_bg.js",
"../../../schema-engine/schema-engine-wasm/pkg/mysql/schema_engine_bg.js",
"../../../schema-engine/schema-engine-wasm/pkg/sqlite/schema_engine_bg.js"
]
},
"keywords": [],
"author": "",
"sideEffects": false,
Expand Down
20 changes: 8 additions & 12 deletions libs/driver-adapters/executor/src/query-engine-wasm.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import * as wasmPostgres from '../../../../query-engine/query-engine-wasm/pkg/postgresql/query_engine_bg.js'
import * as wasmMysql from '../../../../query-engine/query-engine-wasm/pkg/mysql/query_engine_bg.js'
import * as wasmSqlite from '../../../../query-engine/query-engine-wasm/pkg/sqlite/query_engine_bg.js'
import fs from 'node:fs/promises'
import path from 'node:path'
import { __dirname } from './utils'
import type { Queryable } from '@prisma/driver-adapter-utils'

const wasm = {
postgres: wasmPostgres,
mysql: wasmMysql,
sqlite: wasmSqlite,
function loadEngine(provider: Queryable['provider']) {
const normalisedProvider = provider === 'postgres' ? 'postgresql' : provider
const relativePath = '../../../../query-engine/query-engine-wasm/pkg'
return import(`${relativePath}/${normalisedProvider}/query_engine_bg.js`)
}

type EngineName = keyof typeof wasm
const initializedModules = new Set<Queryable['provider']>()

const initializedModules = new Set<EngineName>()

export async function getQueryEngineForProvider(provider: EngineName) {
const engine = wasm[provider]
export async function getQueryEngineForProvider(provider: Queryable['provider']) {
const engine = await loadEngine(provider)
if (!initializedModules.has(provider)) {
const subDir = provider === 'postgres' ? 'postgresql' : provider
const bytes = await fs.readFile(
Expand Down
20 changes: 8 additions & 12 deletions libs/driver-adapters/executor/src/schema-engine-wasm.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
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'
import fs from 'node:fs/promises'
import path from 'node:path'
import type { Queryable } from '@prisma/driver-adapter-utils'
import { __dirname } from './utils.js'

const wasm = {
postgres: wasmPostgres,
mysql: wasmMysql,
sqlite: wasmSqlite
function loadEngine(provider: Queryable['provider']) {
const normalisedProvider = provider === 'postgres' ? 'postgresql' : provider
const relativePath = '../../../../schema-engine/schema-engine-wasm/pkg'
return import(`${relativePath}/${normalisedProvider}/query_engine_bg.js`)
}

type EngineName = keyof typeof wasm
const initializedModules = new Set<Queryable['provider']>()

const initializedModules = new Set<EngineName>()

export async function getSchemaEngineForProvider(provider: EngineName) {
const engine = wasm[provider]
export async function getSchemaEngineForProvider(provider: Queryable['provider']) {
const engine = await loadEngine(provider)
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'))
Expand Down

0 comments on commit 737b8b6

Please sign in to comment.