Skip to content

Commit

Permalink
fix: broken import of libsql client
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jun 19, 2024
1 parent 9fc57d6 commit 1afc648
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
15 changes: 8 additions & 7 deletions src/clients/libsql.cjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
const Sqlite3Client = require('knex/lib/dialects/sqlite3')

class LibSQLClient extends Sqlite3Client {
module.exports = class LibSQLClient extends Sqlite3Client {
_driver() {
return require('@libsql/sqlite3')
}
}

Object.assign(LibSQLClient.prototype, {
dialect: 'libsql',
driverName: 'libsql',
})
get dialect() {
return 'libsql'
}

module.exports = LibSQLClient
get driverName() {
return 'libsql'
}
}
5 changes: 2 additions & 3 deletions src/connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ import type { Logger } from '@adonisjs/core/logger'
import { resolveClientNameWithAliases } from 'knex/lib/util/helpers.js'

import * as errors from '../errors.js'
import { clientsNames } from '../dialects/index.js'
// @ts-expect-error
import LibSQLClient from '../clients/libsql.cjs'
import { clientsNames } from '../dialects/index.js'
import { Logger as ConnectionLogger } from './logger.js'
import type { ConnectionConfig, ConnectionContract } from '../types/database.js'

Expand Down Expand Up @@ -156,7 +155,7 @@ export class Connection extends EventEmitter implements ConnectionContract {
if (this.config.client === 'libsql') {
return {
...this.config,
client: LibSQLClient,
client: LibSQLClient as any,
}
}

Expand Down
6 changes: 2 additions & 4 deletions test-helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {

import { BaseSchema } from '../src/schema/main.js'
import { Database } from '../src/database/main.js'
import LibSQLClient from '../src/clients/libsql.cjs'
import { Adapter } from '../src/orm/adapter/index.js'
import { BaseModel } from '../src/orm/base_model/index.js'
import { QueryClient } from '../src/query_client/index.js'
Expand All @@ -43,9 +44,6 @@ import { InsertQueryBuilder } from '../src/database/query_builder/insert.js'
import { LucidRow, LucidModel, AdapterContract } from '../src/types/model.js'
import { DatabaseQueryBuilder } from '../src/database/query_builder/database.js'

// @ts-expect-error
import LibSQLClient from '../src/clients/libsql.cjs'

dotenv.config()
export const APP_ROOT = new URL('./tmp', import.meta.url)
export const SQLITE_BASE_PATH = fileURLToPath(APP_ROOT)
Expand Down Expand Up @@ -159,7 +157,7 @@ export function getKnex(config: knex.Knex.Config): knex.Knex {
{},
{
...config,
client: config.client === 'libsql' ? LibSQLClient : config.client,
client: config.client === 'libsql' ? (LibSQLClient as any) : config.client,
},
{ debug: false }
)
Expand Down
Binary file modified test-helpers/tmp/libsql.db
Binary file not shown.
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "@adonisjs/tsconfig/tsconfig.package.json",
"compilerOptions": {
"rootDir": "./",
"outDir": "./build"
"outDir": "./build",
"allowJs": true
}
}

0 comments on commit 1afc648

Please sign in to comment.