WiseLibs / better-sqlite3

The fastest and simplest library for SQLite3 in Node.js.
MIT License
5.23k stars 390 forks source link

Allow easy way to get Sqlite3 version #1122

Closed code-ape closed 5 months ago

code-ape commented 6 months ago

In working with better-sqlite3 we wanted to check the exact version of sqlite3 being used to ensure a feature was available or throw an error. There does not appear to be any way to get the sqlite3 version out of better-sqlite3 right now.

Suggestion of something like:

console.log(db.sqlite3Version)
// 3.44.2

Related Issues & PRs:

  1. https://github.com/knex/knex/pull/5782
Prinzhorn commented 6 months ago

https://github.com/WiseLibs/better-sqlite3/issues/1021

code-ape commented 6 months ago

Thanks @Prinzhorn, I've opened a PR which addresses both this and #1124:

mceachen commented 6 months ago

fwiw, the built-in sqlite_version() function will return this value:

const bs = require("better-sqlite3");

function sqliteVersion() {
  let db;
  try {
    db = new bs(":memory:");
    return db.prepare("select sqlite_version()").pluck().get();
  } finally {
    db?.close();
  }
}

console.log(sqliteVersion());

Emits 3.44.2