← All projects
Project record1 mention
Originally shared on Hacker News

litesql

litesql is a Go library that provides an abstraction for correctly using SQLite in Go programs. It pools connections for read transactions, isolates a dedicated write connection for writes, sets more reasonable pragma defaults (isolation levels, foreign keys, cache sizes), offers an abstraction for creating periodic snapshots with retention policies, and includes litesqltest for one-line test database creation in unit tests.

Last shared For Go developers
01 / The problem

What it addresses

Using SQLite in Go with the default database/sql driver works until SQLITE_BUSY errors appear as traffic increases, and developers face conflicting information on best practices for pragma values and connection handling.

02 / Source history

Shared over time

Each entry reflects what was shared on that date. Details may have changed since then.

  1. litesql

    litesql is a Go library that provides an abstraction for correctly using SQLite in Go programs. It pools connections for read transactions, isolates a dedicated write connection for writes, sets more reasonable pragma defaults (isolation levels, foreign keys, cache sizes), offers an abstraction for creating periodic snapshots with retention policies, and includes litesqltest for one-line test database creation in unit tests.

    Problem: Using SQLite in Go with the default database/sql driver works until SQLITE_BUSY errors appear as traffic increases, and developers face conflicting information on best practices for pragma values and connection handling.

    Audience: Go developers

    Posted by @sethops1 · Original source ↗

    Submitted URL · @sethops1 · · Source ↗

    https://github.com/cattlecloud/litesql

    Source text · @sethops1 · · Source ↗

    Which provides a nice abstraction, making it easy to accidentally do the right things when using SQLite in your Go program.

    Source text · @sethops1 · · Source ↗

    In particular it pools connections for read transactions and isolates a dedicated write connection for writes. It also sets pragma values to much more reasonable defaults, like isolation levels, foreign keys, cache sizes, etc.

    Source text · @sethops1 · · Source ↗

    If you just import the popular github.com/mattn/go-sqlite3 as the database/sql driver implementation and start making queries, things will work great until you start hitting SQLITE_BUSY errors as traffic increases.

    Source text · @sethops1 · · Source ↗

    Then you go down the same path of many gophers before you, finding GitHub and forum posts providing conflicting information on best practices for pragma values and connection handling.

    Story title · @sethops1 · · Source ↗

    Show HN: I created a library for correctly using SQLite in Go programs