ard-sql

module
v0.0.0-...-abed37e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2026 License: MIT

README

sql

A small Ard wrapper around Go's database/sql package.

It provides a consistent API for PostgreSQL, SQLite, and MySQL using pure-Go drivers, including named parameters, transactions, and query results represented as opaque Ard Any values.

Requirements

  • Ard 0.26.0 or newer

Installation

ard add github.com/akonwi/ard-sql@latest as sql

Then import the module:

use sql

For local development:

[dependencies]
sql = { path = "../sql" }

Usage

use sql

fn users(database_url: Str) [Any]!Str {
  let db = try sql::open(database_url)
  defer db.close()
  
  let rows = try db
    .query("SELECT id, name FROM users WHERE active = @active")
    .all(["active": true])
  Result::ok(rows)
}

Queries use @name parameters. They are rewritten to the placeholder syntax required by the selected database driver.

Transactions expose the same exec and query operations:

let tx = try db.begin()
try tx.query("DELETE FROM users WHERE id = @id").run(["id": 42])
try tx.commit()

Database URLs

The driver is inferred from the connection string:

  • PostgreSQL: postgres://... or postgresql://...
  • MySQL: DSNs containing @tcp( or @unix(
  • SQLite: all other values, such as :memory: or app.db

API

  • open opens a database connection
  • Database.close closes it
  • Database.exec executes SQL without parameters
  • Database.query creates a parameterized query
  • Database.begin starts a transaction
  • Query.run executes a statement
  • Query.all returns every matching row
  • Query.first returns the first row, if present
  • Transaction.commit and Transaction.rollback complete a transaction

Development

ard format .
ard test
go test ./...

Directories

Path Synopsis
Package ffi bridges Ard lists and row values to database/sql while Ard retains native *sql.DB and *sql.Tx handles.
Package ffi bridges Ard lists and row values to database/sql while Ard retains native *sql.DB and *sql.Tx handles.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL