Skip to content

Commit

Permalink
fix(sqlite): support hybrid require / import
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Mar 25, 2024
1 parent 73c1cb1 commit 1db63a4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/sqlite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@minatojs/driver-sqlite",
"version": "4.0.1",
"version": "4.0.2",
"description": "SQLite Driver for Minato",
"type": "module",
"main": "lib/index.cjs",
Expand Down
5 changes: 4 additions & 1 deletion packages/sqlite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { Driver, Eval, executeUpdate, Field, Selection, z } from 'minato'
import { escapeId } from '@minatojs/sql-utils'
import { resolve } from 'node:path'
import { readFile, writeFile } from 'node:fs/promises'
import { createRequire } from 'node:module'
import init from '@minatojs/sql.js'
import enUS from './locales/en-US.yml'
import zhCN from './locales/zh-CN.yml'
import { SQLiteBuilder } from './builder'
import { pathToFileURL } from 'node:url'

function getTypeDef({ type }: Field) {
switch (type) {
Expand Down Expand Up @@ -156,7 +158,8 @@ export class SQLiteDriver extends Driver<SQLiteDriver.Config> {
? process.env.KOISHI_BASE + '/' + file
: isBrowser
? '/modules/@koishijs/plugin-database-sqlite/' + file
: require.resolve('@minatojs/sql.js/dist/' + file),
// @ts-ignore
: createRequire(import.meta.url || pathToFileURL(__filename).href).resolve('@minatojs/sql.js/dist/' + file),
})
if (!isBrowser || this.config.path === ':memory:') {
this.db = new sqlite.Database(this.config.path)
Expand Down

0 comments on commit 1db63a4

Please sign in to comment.