Skip to content

Latest commit

 

History

History
220 lines (155 loc) · 5.21 KB

File metadata and controls

220 lines (155 loc) · 5.21 KB

How to install an extension

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

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 macOS
  • sqlean-macos-arm64.zip - Apple silicon (ARM-based) macOS

Binaries are 64-bit and require a 64-bit SQLite version.

Install: Command-line interface

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.

Install: GUI database browser

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');

Install: rqlite

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.zip

Then pass the zipfile to rqlite when you start the rqlite node:

rqlited -extensions-path=sqlean.zip data

See full details on rqlite.io.

Install: Python

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.

Install: Node.js

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();

Install: Browser JavaScript

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)");
});

Install: Go

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.