sqlx

v0.0.43

High-level SQL API

Install
Install
riot add sqlx
riot.toml
sqlx = "0.0.43"
Last release
May 15, 2026
License
Apache-2.0
Dependencies
4
Dependents
1
Installs
27
Published versions
33
Owner
@leostera@leostera
README Expand

sqlx

High-level SQL API for Riot.

sqlx gives you a database-facing API with connection pooling, transactions, queries, typed value/row abstractions, and migration management. It does not tie you to one backend: you provide a concrete driver such as sqlite, postgres, or mysql.

Install

riot add sqlx

What you get

  • connection pool management;
  • query and exec helpers over a shared value model;
  • transaction support;
  • SQL migration resolution and execution;
  • a backend-neutral surface that works with multiple drivers.

Minimal query shape

open Sqlx

let start = fun database_url ->
  match Postgres.Config.from_string database_url with
  | Error message -> Error message
  | Ok config -> (
      match Sqlx.connect ~driver:(module Postgres.Driver) config with
      | Error error -> Error (Sqlx.show_error error)
      | Ok pool -> Ok pool
    )

From there you can call Sqlx.query, Sqlx.exec, and Sqlx.with_transaction.

Migrations

Application schema should live in SQL migration files, not inline strings inside runtime modules. By default, Sqlx.migrate pool () resolves files from ./migrations, relative to the process working directory:

let start = fun database_url ->
  match Postgres.Config.from_string database_url with
  | Error message -> Error message
  | Ok config -> (
      match Sqlx.connect ~driver:(module Postgres.Driver) config with
      | Error error -> Error (Sqlx.show_error error)
      | Ok pool -> (
          let migration_config = Sqlx.Migrate.Config.for_postgres () in
          match Sqlx.migrate ~config:migration_config pool () with
          | Ok () -> Ok pool
          | Error error ->
              Sqlx.shutdown pool;
              Error (Sqlx.Migrate.error_to_string error)
        )
    )

Migration filenames follow the same shape as sqlx-rs:

  • 1_create_users.sql for a simple forward-only migration;
  • 2_add_orders.up.sql for the forward side of a reversible migration;
  • 2_add_orders.down.sql for the rollback side of a reversible migration.

Descriptions are derived from the filename after the version prefix, with underscores rendered as spaces. Migrations are sorted by numeric version before execution.

Use -- no-transaction as the first line when a migration must run outside a transaction. Prefer transactional migrations whenever the database supports them. MySQL configs default to non-transactional migration bodies because MySQL DDL commonly commits implicitly.

Use Sqlx.Migrate.run instead of Sqlx.migrate when you need the full report of applied migrations and already-applied versions:

let source = Sqlx.Migrate.Source.from_directory (Path.v "migrations")
let config = Sqlx.Migrate.Config.for_postgres ()
let result = Sqlx.Migrate.run ~config pool source

For MySQL/InnoDB, use the MySQL config helper:

let source = Sqlx.Migrate.Source.from_directory (Path.v "migrations")
let config = Sqlx.Migrate.Config.for_mysql ()
let result = Sqlx.Migrate.run ~config pool source

MySQL migration files may contain multiple semicolon-terminated statements. SQLx passes the raw migration body to the active driver; the MySQL driver prepares it as individual statements and ignores semicolons inside single-quoted strings, double-quoted strings, backtick identifiers, line comments, and block comments. MySQL client-only DELIMITER commands are not interpreted.

If your application starts from a different working directory, pass an explicit source:

let source = Sqlx.Migrate.Source.from_directory (Path.v "/opt/app/migrations")
let result = Sqlx.migrate ~source pool ()

The migrator stores applied versions, checksums, and execution durations in _sqlx_migrations by default. On startup it rejects dirty databases, missing applied migrations, and modified applied migrations unless the migration config explicitly opts out of the missing-file check.

Backend-specific migration config controls placeholders, migration-table DDL, locking, and transaction defaults. PostgreSQL uses advisory locks and $1 placeholders. MySQL uses GET_LOCK/RELEASE_LOCK, ? placeholders, and an InnoDB migration table. Migration-table text fields are decoded from either driver text values or byte values, which matches MySQL's TEXT wire metadata.

Which driver should you use?

  • sqlite is great for local tools, tests, and embedded data.
  • postgres is the choice when you need a long-running server database.
  • mysql is the MySQL/InnoDB driver and uses ? placeholders.

Where to start

  • src/sqlx.mli is the main public API.
  • src/migrate.mli documents migration resolution and execution.
  • tests/sqlx_tests.ml, tests/pool_tests.ml, and tests/migrate_tests.ml show the expected behavior.
Installs
Downloads over the last 30 days, stacked by release.
Total installs
27
Downloads over the last 30 days
v0.0.430
v0.0.420
v0.0.410
v0.0.4013
v0.0.390
Package status
Submission, indexing, and post-publish processing milestones for this release.
Submitted
May 15, 08:09 PM
Indexed
May 15, 08:09 PM
Searchable
May 15, 08:09 PM
Docs ready
May 15, 08:30 PM
Completed
Pending
Dependencies
Dependencies declared for this release.
Show 4 dependencies Expand
Dependents
Packages that currently depend on sqlx.
Show 1 dependents Expand
Recent activity
Latest publication, indexing, and post-publish pipeline events recorded for this package.
Open full activity
Show 12 recent events Expand
  • Blocked
    sqlx 0.0.43 attempt 3 · artifact a96f871c3dfd
    Details
    When
    May 15, 2026, 08:44:46 PM
    Event
    Blocked
    Package
    sqlx
    Version
    0.0.43
    Facts
    attempt 3 artifact a96f871c3dfd
    Payload
    {
      "artifact_sha256": "a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323",
      "status": "blocked",
      "attempt_count": 3,
      "error": "error: Unknown argument: sqlx"
    }
  • Build failed
    sqlx 0.0.43 build · exit 1 · artifact a96f871c3dfd
    Details
    When
    May 15, 2026, 08:44:44 PM
    Event
    Build failed
    Package
    sqlx
    Version
    0.0.43
    Summary
    error: Unknown argument: sqlx
    Facts
    build exit 1 artifact a96f871c3dfd
    Artifacts
    Result key
    pipelines/builds/sqlx/0.0.43/a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323/result.json
    Logs key
    pipelines/builds/sqlx/0.0.43/a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323/build.log
    Payload
    {
      "artifact_sha256": "a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323",
      "run_kind": "build",
      "result_key": "pipelines/builds/sqlx/0.0.43/a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323/result.json",
      "logs_key": "pipelines/builds/sqlx/0.0.43/a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323/build.log",
      "environment_probe": {
        "success": true,
        "exit_code": 0,
        "stdout": "glibc=glibc 2.39\nriot=riot 0.0.43 (build 2a3a2071a5f0)\nPRETTY_NAME=\"Ubuntu 24.04.4 LTS\"\nNAME=\"Ubuntu\"\nVERSION_ID=\"24.04\"\nVERSION=\"24.04.4 LTS (Noble Numbat)\"\nVERSION_CODENAME=noble\nID=ubuntu\nID_LIKE=debian\nHOME_URL=\"https://www.ubuntu.com/\"\nSUPPORT_URL=\"https://help.ubuntu.com/\"\nBUG_REPORT_URL=\"https://bugs.launchpad.net/ubuntu/\"\nPRIVACY_POLICY_URL=\"https://www.ubuntu.com/legal/terms-and-policies/privacy-policy\"\nUBUNTU_CODENAME=noble\nLOGO=ubuntu-logo",
        "stderr": "",
        "duration_ms": 96,
        "command": [
          "sh",
          "-lc",
          "printf 'glibc=%s\\n' \"$(getconf GNU_LIBC_VERSION 2>/dev/null || echo unknown)\" && printf 'riot=%s\\n' \"$(/root/.riot/bin/riot version 2>/dev/null || echo unavailable)\" && cat /etc/os-release"
        ],
        "json_events": [],
        "non_json_stdout_lines": [
          "glibc=glibc 2.39",
          "riot=riot 0.0.43 (build 2a3a2071a5f0)",
          "PRETTY_NAME=\"Ubuntu 24.04.4 LTS\"",
          "NAME=\"Ubuntu\"",
          "VERSION_ID=\"24.04\"",
          "VERSION=\"24.04.4 LTS (Noble Numbat)\"",
          "VERSION_CODENAME=noble",
          "ID=ubuntu",
          "ID_LIKE=debian",
          "HOME_URL=\"https://www.ubuntu.com/\"",
          "SUPPORT_URL=\"https://help.ubuntu.com/\"",
          "BUG_REPORT_URL=\"https://bugs.launchpad.net/ubuntu/\"",
          "PRIVACY_POLICY_URL=\"https://www.ubuntu.com/legal/terms-and-policies/privacy-policy\"",
          "UBUNTU_CODENAME=noble",
          "LOGO=ubuntu-logo"
        ]
      },
      "exit_code": 1,
      "json_event_count": 0,
      "non_json_stdout_count": 1,
      "failure_summary": "error: Unknown argument: sqlx",
      "stdout_excerpt": "error: Unknown argument: sqlx"
    }
  • Processing
    sqlx 0.0.43 attempt 3 · artifact a96f871c3dfd
    Details
    When
    May 15, 2026, 08:44:39 PM
    Event
    Processing
    Package
    sqlx
    Version
    0.0.43
    Facts
    attempt 3 artifact a96f871c3dfd
    Payload
    {
      "artifact_sha256": "a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323",
      "status": "processing",
      "attempt_count": 3
    }
  • Requeued
    sqlx 0.0.43 attempt 2 · artifact a96f871c3dfd
    Details
    When
    May 15, 2026, 08:39:06 PM
    Event
    Requeued
    Package
    sqlx
    Version
    0.0.43
    Facts
    attempt 2 artifact a96f871c3dfd
    Payload
    {
      "artifact_sha256": "a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323",
      "status": "pending",
      "attempt_count": 2,
      "next_attempt_at": "2026-05-15T20:44:06.702Z",
      "error": "error: Unknown argument: sqlx"
    }
  • Build failed
    sqlx 0.0.43 build · exit 1 · artifact a96f871c3dfd
    Details
    When
    May 15, 2026, 08:39:05 PM
    Event
    Build failed
    Package
    sqlx
    Version
    0.0.43
    Summary
    error: Unknown argument: sqlx
    Facts
    build exit 1 artifact a96f871c3dfd
    Artifacts
    Result key
    pipelines/builds/sqlx/0.0.43/a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323/result.json
    Logs key
    pipelines/builds/sqlx/0.0.43/a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323/build.log
    Payload
    {
      "artifact_sha256": "a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323",
      "run_kind": "build",
      "result_key": "pipelines/builds/sqlx/0.0.43/a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323/result.json",
      "logs_key": "pipelines/builds/sqlx/0.0.43/a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323/build.log",
      "environment_probe": {
        "success": true,
        "exit_code": 0,
        "stdout": "glibc=glibc 2.39\nriot=riot 0.0.43 (build 2a3a2071a5f0)\nPRETTY_NAME=\"Ubuntu 24.04.4 LTS\"\nNAME=\"Ubuntu\"\nVERSION_ID=\"24.04\"\nVERSION=\"24.04.4 LTS (Noble Numbat)\"\nVERSION_CODENAME=noble\nID=ubuntu\nID_LIKE=debian\nHOME_URL=\"https://www.ubuntu.com/\"\nSUPPORT_URL=\"https://help.ubuntu.com/\"\nBUG_REPORT_URL=\"https://bugs.launchpad.net/ubuntu/\"\nPRIVACY_POLICY_URL=\"https://www.ubuntu.com/legal/terms-and-policies/privacy-policy\"\nUBUNTU_CODENAME=noble\nLOGO=ubuntu-logo",
        "stderr": "",
        "duration_ms": 51,
        "command": [
          "sh",
          "-lc",
          "printf 'glibc=%s\\n' \"$(getconf GNU_LIBC_VERSION 2>/dev/null || echo unknown)\" && printf 'riot=%s\\n' \"$(/root/.riot/bin/riot version 2>/dev/null || echo unavailable)\" && cat /etc/os-release"
        ],
        "json_events": [],
        "non_json_stdout_lines": [
          "glibc=glibc 2.39",
          "riot=riot 0.0.43 (build 2a3a2071a5f0)",
          "PRETTY_NAME=\"Ubuntu 24.04.4 LTS\"",
          "NAME=\"Ubuntu\"",
          "VERSION_ID=\"24.04\"",
          "VERSION=\"24.04.4 LTS (Noble Numbat)\"",
          "VERSION_CODENAME=noble",
          "ID=ubuntu",
          "ID_LIKE=debian",
          "HOME_URL=\"https://www.ubuntu.com/\"",
          "SUPPORT_URL=\"https://help.ubuntu.com/\"",
          "BUG_REPORT_URL=\"https://bugs.launchpad.net/ubuntu/\"",
          "PRIVACY_POLICY_URL=\"https://www.ubuntu.com/legal/terms-and-policies/privacy-policy\"",
          "UBUNTU_CODENAME=noble",
          "LOGO=ubuntu-logo"
        ]
      },
      "exit_code": 1,
      "json_event_count": 0,
      "non_json_stdout_count": 1,
      "failure_summary": "error: Unknown argument: sqlx",
      "stdout_excerpt": "error: Unknown argument: sqlx"
    }
  • Processing
    sqlx 0.0.43 attempt 2 · artifact a96f871c3dfd
    Details
    When
    May 15, 2026, 08:39:00 PM
    Event
    Processing
    Package
    sqlx
    Version
    0.0.43
    Facts
    attempt 2 artifact a96f871c3dfd
    Payload
    {
      "artifact_sha256": "a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323",
      "status": "processing",
      "attempt_count": 2
    }
  • Requeued
    sqlx 0.0.43 attempt 1 · artifact a96f871c3dfd
    Details
    When
    May 15, 2026, 08:31:02 PM
    Event
    Requeued
    Package
    sqlx
    Version
    0.0.43
    Facts
    attempt 1 artifact a96f871c3dfd
    Payload
    {
      "artifact_sha256": "a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323",
      "status": "pending",
      "attempt_count": 1,
      "next_attempt_at": "2026-05-15T20:36:02.830Z",
      "error": "error: Unknown argument: sqlx"
    }
  • Docs ready
    sqlx 0.0.43 docs · 2 json · doc.package_generation_completed · artifact a96f871c3dfd
    Details
    When
    May 15, 2026, 08:30:38 PM
    Event
    Docs ready
    Package
    sqlx
    Version
    0.0.43
    Facts
    docs 2 json doc.package_generation_completed artifact a96f871c3dfd
    Artifacts
    Result key
    pipelines/docs/sqlx/0.0.43/a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323/result.json
    Logs key
    pipelines/docs/sqlx/0.0.43/a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323/command.log
    Payload
    {
      "artifact_sha256": "a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323",
      "run_kind": "docs",
      "output_prefix": "docs/sqlx/0.0.43/",
      "public_docs_url": "https://docs.pkgs.ml/p/sqlx/0.0.43/",
      "result_key": "pipelines/docs/sqlx/0.0.43/a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323/result.json",
      "logs_key": "pipelines/docs/sqlx/0.0.43/a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323/command.log",
      "json_event_count": 2,
      "non_json_stdout_count": 0,
      "last_json_event_type": "doc.package_generation_completed"
    }
  • Build failed
    sqlx 0.0.43 build · exit 1 · artifact a96f871c3dfd
    Details
    When
    May 15, 2026, 08:30:36 PM
    Event
    Build failed
    Package
    sqlx
    Version
    0.0.43
    Summary
    error: Unknown argument: sqlx
    Facts
    build exit 1 artifact a96f871c3dfd
    Artifacts
    Result key
    pipelines/builds/sqlx/0.0.43/a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323/result.json
    Logs key
    pipelines/builds/sqlx/0.0.43/a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323/build.log
    Payload
    {
      "artifact_sha256": "a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323",
      "run_kind": "build",
      "result_key": "pipelines/builds/sqlx/0.0.43/a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323/result.json",
      "logs_key": "pipelines/builds/sqlx/0.0.43/a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323/build.log",
      "environment_probe": {
        "success": true,
        "exit_code": 0,
        "stdout": "glibc=glibc 2.39\nriot=riot 0.0.43 (build 2a3a2071a5f0)\nPRETTY_NAME=\"Ubuntu 24.04.4 LTS\"\nNAME=\"Ubuntu\"\nVERSION_ID=\"24.04\"\nVERSION=\"24.04.4 LTS (Noble Numbat)\"\nVERSION_CODENAME=noble\nID=ubuntu\nID_LIKE=debian\nHOME_URL=\"https://www.ubuntu.com/\"\nSUPPORT_URL=\"https://help.ubuntu.com/\"\nBUG_REPORT_URL=\"https://bugs.launchpad.net/ubuntu/\"\nPRIVACY_POLICY_URL=\"https://www.ubuntu.com/legal/terms-and-policies/privacy-policy\"\nUBUNTU_CODENAME=noble\nLOGO=ubuntu-logo",
        "stderr": "",
        "duration_ms": 64,
        "command": [
          "sh",
          "-lc",
          "printf 'glibc=%s\\n' \"$(getconf GNU_LIBC_VERSION 2>/dev/null || echo unknown)\" && printf 'riot=%s\\n' \"$(/root/.riot/bin/riot version 2>/dev/null || echo unavailable)\" && cat /etc/os-release"
        ],
        "json_events": [],
        "non_json_stdout_lines": [
          "glibc=glibc 2.39",
          "riot=riot 0.0.43 (build 2a3a2071a5f0)",
          "PRETTY_NAME=\"Ubuntu 24.04.4 LTS\"",
          "NAME=\"Ubuntu\"",
          "VERSION_ID=\"24.04\"",
          "VERSION=\"24.04.4 LTS (Noble Numbat)\"",
          "VERSION_CODENAME=noble",
          "ID=ubuntu",
          "ID_LIKE=debian",
          "HOME_URL=\"https://www.ubuntu.com/\"",
          "SUPPORT_URL=\"https://help.ubuntu.com/\"",
          "BUG_REPORT_URL=\"https://bugs.launchpad.net/ubuntu/\"",
          "PRIVACY_POLICY_URL=\"https://www.ubuntu.com/legal/terms-and-policies/privacy-policy\"",
          "UBUNTU_CODENAME=noble",
          "LOGO=ubuntu-logo"
        ]
      },
      "exit_code": 1,
      "json_event_count": 0,
      "non_json_stdout_count": 1,
      "failure_summary": "error: Unknown argument: sqlx",
      "stdout_excerpt": "error: Unknown argument: sqlx"
    }
  • Processing
    sqlx 0.0.43 attempt 1 · artifact a96f871c3dfd
    Details
    When
    May 15, 2026, 08:30:25 PM
    Event
    Processing
    Package
    sqlx
    Version
    0.0.43
    Facts
    attempt 1 artifact a96f871c3dfd
    Payload
    {
      "artifact_sha256": "a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323",
      "status": "processing",
      "attempt_count": 1
    }
  • Queued
    sqlx 0.0.43 artifact a96f871c3dfd
    Details
    When
    May 15, 2026, 08:09:57 PM
    Event
    Queued
    Package
    sqlx
    Version
    0.0.43
    Facts
    artifact a96f871c3dfd
    Payload
    {
      "artifact_sha256": "a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323",
      "status": "pending"
    }
  • Indexed
    sqlx 0.0.43 latest 0.0.43 · artifact a96f871c3dfd
    Details
    When
    May 15, 2026, 08:09:54 PM
    Event
    Indexed
    Package
    sqlx
    Version
    0.0.43
    Facts
    latest 0.0.43 artifact a96f871c3dfd
    Payload
    {
      "artifact_sha256": "a96f871c3dfdbee6f2486cd765edeacbf612ffd6c319d9da915e532f58c7c323",
      "latest": "0.0.43",
      "package_index_key": "index/v1/sq/lx/sqlx.json",
      "package_index_url": "https://cdn.pkgs.ml/index/v1/sq/lx/sqlx.json",
      "changed": true
    }