All news

Published

SQLite package now available

The sqlite package is now available in the Jik packages repository. It provides database connections, SQL execution, prepared statements, result reading, and close operations.

Import it with use "pkg/sqlite". The package links a bundled SQLite library, so programs built with it do not need a separate SQLite DLL or shared library alongside the executable.

use "pkg/sqlite"

func main():
    database := must sqlite::open(":memory:", _)
    must sqlite::exec(database, "create table item (id integer, name text)")

    insert := must sqlite::prepare(database, "insert into item values (?, ?)", _)
    must sqlite::bind_int(insert, 1, 1)
    must sqlite::bind_text(insert, 2, "Ada")
    must sqlite::step(insert)
    must sqlite::finalize(insert)

    query := must sqlite::prepare(database, "select name from item where id = ?", _)
    must sqlite::bind_int(query, 1, 1)
    if must sqlite::step(query):
        println(must sqlite::column_text(query, 0, _))
    end
    must sqlite::finalize(query)
    must sqlite::close(database)
end