Warning
These bindings were hand-written and thus can contain many mistakes. In case you found a mistake consider opening up an issue or making a pull request.
This repository contains sqlite3 bindings and a wrapper library for Odin.
/amalgamation/: sqlite3's official amalgamation of the source code. Replace the contents of the folder with fresh version of amalgamation to update the version./bindings/: Raw bindings of sqlite3./bindings/bin/: Compiled binaries of the sqlite3 library./wrapper/: A more convenient interface to the sqlite3 library./test/: An example of using the sqlite3 wrapper.
- Clone this repository.
- Build the binaries:
- Windows: Run
./build-cl.bat, in case you want to build with MSVC compiler; or./build-clang-windows.batto build the clang. - Linux: Run
./build-clang-linux
- Windows: Run
- Copy the files to your project:
- Just the bindings: copy
/bindingsdirectories. - With the wrapper: copy
/bindingsand/wrapperdirectories.
- Just the bindings: copy
DB_FILE :: "test/db.sqlite"
db, status := sqlite.open(DB_FILE)
if status != nil {
fmt.eprintf("Unable to open database '%s'(%v): %s", DB_FILE, status, sqlite.status_explain(status))
os.exit(1)
}
// Do things with database
sqlite.close(db)sqlite.sql_exec(db, `
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY
, name VARCHAR(64) NOT NULL
, flag INTEGER NOT NULL
);
INSERT INTO users (name, flag) VALUES
('john', 1)
, ('mary', 0)
, ('alice', 1)
, ('bob', 0);
`)// Create prepared statement
query, _ := sqlite.sql_bind(db, `
SELECT
name
, flag
FROM users
WHERE flag = ?1;
`, false)
// Iterate the results
for row in sqlite.sql_row(db, query, struct { name: string, ok: bool }) {
fmt.printf("ROW: %v\n", row)
}