Examples below use the stats extension; you can specify any other supported extension. To load all extensions at once, use the single-file sqlean bundle.
- Download
- Install: Command-line interface
- Install: GUI database browser
- Install: rqlite
- Install: Python
- Install: Node.js
- Install: Browser JavaScript
- Install: Go
There are precompiled binaries for every OS:
sqlean-win-x64.zip- Windows (Intel/AMD x64 CPU)sqlean-linux-x64.zip- Linux (Intel/AMD x64 CPU)sqlean-linux-arm64.zip- Linux (ARM CPU)sqlean-macos-x64.zip- Intel-based macOSsqlean-macos-arm64.zip- Apple silicon (ARM-based) macOS
Binaries are 64-bit and require a 64-bit SQLite version.
SQLite CLI, also known as SQLite shell, is a console interface (sqlite3.exe on Windows, sqlite3 on Linux/macOS).
Start it and load the extension with the .load command:
Windows:
.load c:/Users/anton/Downloads/stats
Linux/macOS:
.load /Users/anton/Downloads/stats
Now you can use the extension! For example, the stats extension adds the median and generate_series functions:
select median(value) from generate_series(1, 99);Note for macOS users. macOS may disable unsigned binaries and prevent the extension from loading. To resolve this issue, remove the extension from quarantine by running the following command in Terminal:
xattr -d com.apple.quarantine /Users/anton/Downloads/stats.dylib
Also note that the "stock" SQLite CLI on macOS might not support extensions.
To load extension in SQLiteStudio, SQLiteSpy, DBeaver and other similar tools, use the load_extension function.
Windows:
select load_extension('c:\Users\anton\Downloads\stats');Linux/macOS:
select load_extension('/Users/anton/Downloads/stats');To load extensions in rqlite, first download a suitable release (x64 for Linux is demonstrated below):
curl -L https://github.com/nalgeon/sqlean/releases/latest/download/sqlean-linux-x64.zip -o sqlean.zipThen pass the zipfile to rqlite when you start the rqlite node:
rqlited -extensions-path=sqlean.zip dataSee full details on rqlite.io.
Use the default sqlite3 module to load the extension.
Windows:
import sqlite3
conn = sqlite3.connect(":memory:")
conn.enable_load_extension(True)
conn.load_extension(r"c:\Users\anton\Downloads\stats")
conn.execute("select median(value) from generate_series(1, 99)")
conn.close()Linux/macOS:
import sqlite3
conn = sqlite3.connect(":memory:")
conn.enable_load_extension(True)
conn.load_extension("/Users/anton/Downloads/stats")
conn.execute("select median(value) from generate_series(1, 99)")
conn.close()Note that the "stock" SQLite on macOS might not support extensions, so this method might not work.
Use the better-sqlite3 package.
Windows:
const sqlite3 = require("better-sqlite3");
const db = new sqlite3(":memory:");
db.loadExtension(`c:\Users\anton\Downloads\stats`);
db.exec("select median(value) from generate_series(1, 99)");
db.close();Linux/macOS:
const sqlite3 = require("better-sqlite3");
const db = new sqlite3(":memory:");
db.loadExtension("/Users/anton/Downloads/stats");
db.exec("select median(value) from generate_series(1, 99)");
db.close();Use the sqlean.js package:
import sqlite3Init from "./sqlean.mjs";
async function init() {
return await sqlite3Init({
print: console.log,
printErr: console.error,
});
}
init().then((sqlite3) => {
const db = new sqlite3.oo1.DB();
db.exec("select median(value) from generate_series(1, 99)");
});Use the mattn/go-sqlite3 package.
Windows:
package main
import (
"database/sql"
"fmt"
sqlite3 "github.com/mattn/go-sqlite3"
)
func main() {
sql.Register("sqlite_ext",
&sqlite3.SQLiteDriver{
Extensions: []string{
`c:\Users\anton\sqlDownloadsite\stats`,
},
})
db, err := sql.Open("sqlite_ext", ":memory:")
db.Query("select median(value) from generate_series(1, 99)")
db.Close()
}Linux/macOS:
package main
import (
"database/sql"
"fmt"
sqlite3 "github.com/mattn/go-sqlite3"
)
func main() {
sql.Register("sqlite_ext",
&sqlite3.SQLiteDriver{
Extensions: []string{
"/Users/anton/Downloads/stats",
},
})
db, err := sql.Open("sqlite_ext", ":memory:")
db.Query("select median(value) from generate_series(1, 99)")
db.Close()
}Note that we use the same identifier sqlite_ext in the sql.Register and sql.Open.