Documentation
¶
Overview ¶
Package dbmod is the native module "db": SQL databases through Go's database/sql: SQLite (modernc.org/sqlite), PostgreSQL (jackc/pgx) and MySQL or MariaDB (go-sql-driver/mysql), all pure Go, so no C library is needed.
use db;
local conn = db::open("sqlite:shop.db");
conn->exec("CREATE TABLE IF NOT EXISTS items (name TEXT, price REAL)");
conn->exec("INSERT INTO items VALUES (?, ?)", "pen", 1.5);
for (local row in conn->query("SELECT * FROM items WHERE price < ?", 10))
println(row["name"], row["price"]);
conn->close();
Values always travel as parameters (?), never glued into the SQL text.
Index ¶
Constants ¶
View Source
const DBError = "DBError"
DBError is the kind of the exceptions the database reports: an SQL error, a broken constraint, a database file that cannot be opened.
Variables ¶
View Source
var ( Conn = &native.Class{Name: "Conn"} Cursor = &native.Class{Name: "Cursor"} )
Conn and Cursor are the classes db::Conn and db::Cursor.
View Source
var Query = &native.Class{Name: "Query"}
Query is the class db::Query: conn->find(C) and its refinements.
View Source
var Relation = &native.Class{Name: "Relation", Show: func(o *value.ObjectObj) string {
r := o.State.(*relation)
kind := "one"
if r.many {
kind = "many"
}
return "db::" + kind + "(" + r.class.Name + ", \"" + r.key + "\")"
}}
Relation is the class of what db::many and db::one give.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.