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

Compatible with kysely #77

Open
ci010 opened this issue Jun 28, 2024 · 0 comments
Open

Compatible with kysely #77

ci010 opened this issue Jun 28, 2024 · 0 comments

Comments

@ci010
Copy link

ci010 commented Jun 28, 2024

Current interface is pretty similar to better-sqlite3. So I think it can be easy to work with kysely.

Regardless the statement.finalize call, in kysely, the only thing does not fit is the reader property on Statement, which is used to determine if it's a read operation or write:

  executeQuery<O>(compiledQuery: CompiledQuery): Promise<QueryResult<O>> {
    const { sql, parameters } = compiledQuery
    const stmt = this.#db.prepare(sql)

    if (stmt.reader) {
      return Promise.resolve({
        rows: stmt.all(parameters) as O[],
      })
    } else {
      const { changes, lastInsertRowid } = stmt.run(parameters)

      const numAffectedRows =
        changes !== undefined && changes !== null ? BigInt(changes) : undefined

      return Promise.resolve({
        numUpdatedOrDeletedRows: numAffectedRows,
        numAffectedRows,
        insertId:
          lastInsertRowid !== undefined && lastInsertRowid !== null
            ? BigInt(lastInsertRowid)
            : undefined,
        rows: [],
      })
    }
  }

Possible solution

I read the better-sqlite3 code, the value is like

bool returns_data = sqlite3_column_count(handle) >= 1 || pragmaMode;

(not sure what's the pragmaMode here)

So I guess we should just add

const columns = sqlite3.column_count(this._ptr);
return columns >= 1;

to implement it.

I'm not familiar with sqlite library. If the thought above is doable, I can send PR for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant