{"id":44998162,"url":"https://github.com/cattlecloud/litesql","last_synced_at":"2026-05-10T15:19:09.526Z","repository":{"id":334796637,"uuid":"1142715257","full_name":"cattlecloud/litesql","owner":"cattlecloud","description":"litesql is a Go library for convenient, easy, and performant use of SQLite3 databases in Go programs ","archived":false,"fork":false,"pushed_at":"2026-05-09T18:01:43.000Z","size":43,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-09T18:36:30.920Z","etag":null,"topics":["database","go","golang","library","sqlite"],"latest_commit_sha":null,"homepage":"https://cattlecloud.net/go/litesql","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cattlecloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-26T19:08:29.000Z","updated_at":"2026-05-09T18:01:11.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/cattlecloud/litesql","commit_stats":null,"previous_names":["cattlecloud/litesql"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/cattlecloud/litesql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cattlecloud%2Flitesql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cattlecloud%2Flitesql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cattlecloud%2Flitesql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cattlecloud%2Flitesql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cattlecloud","download_url":"https://codeload.github.com/cattlecloud/litesql/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cattlecloud%2Flitesql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32860514,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-10T13:40:02.631Z","status":"ssl_error","status_checked_at":"2026-05-10T13:40:02.145Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","go","golang","library","sqlite"],"created_at":"2026-02-18T22:02:27.310Z","updated_at":"2026-05-10T15:19:09.519Z","avatar_url":"https://github.com/cattlecloud.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# litesql\n\n[![Go Reference](https://pkg.go.dev/badge/cattlecloud.net/go/litesql.svg)](https://pkg.go.dev/cattlecloud.net/go/litesql)\n[![License](https://img.shields.io/github/license/cattlecloud/litesql?color=7C00D8\u0026style=flat-square\u0026label=License)](https://github.com/cattlecloud/litesql/blob/main/LICENSE)\n[![Build](https://img.shields.io/github/actions/workflow/status/cattlecloud/litesql/ci.yaml?style=flat-square\u0026color=0FAA07\u0026label=Tests)](https://github.com/cattlecloud/litesql/actions/workflows/ci.yaml)\n\n`litesql` is a Go library for working with SQLite3, providing reasonable\ndefaults and an easy-to-use API for reliable and performant database access.\n\n### Getting Started\n\nThe `litesql` package can be added to a Go project with `go get`.\n\n```shell\ngo get cattlecloud.net/go/litesql@latest\n```\n\n```go\nimport \"cattlecloud.net/go/litesql\"\n```\n\n### Examples\n\n#### Opening a SQLite database\n\nThe `litesql.TypicalConfiguration` contains reasonable defaults for many\ngeneral applications such as webapps. You may wish to use it as a reference\nand fine-tune parameters for each use case.\n\n```go\ndb, err := litesql.Open(\"/path/to/file\", litesql.TypicalConfiguration)\n// ...\ndefer db.Close()\n```\n\n#### Starting SQLite transactions\n\nThe `*LiteDB` returned by `Open` provides `StartRead` and `StartWrite` for\nstarting a read or write transaction. They make use of the `ReadConsistency`\nand `WriteConsistency` package values to indicate isolation levels. A write\ntransaction must be ended with a call to `Commit`.\n\n```go\n// read transaction\ntx, done, xerr := db.StartRead(ctx)\nif xerr != nil {\n    return xerr\n}\ndefer done()\n\n// ... use tx to execute queries ...\n```\n\n```go\n// write transaction\ntx, done, xerr = db.StartWrite(ctx)\nif xerr != nil {\n    return xerr\n}\ndefer done()\n\n// ... use tx to execute statements ...\n\n// commit the write transaction\nreturn tx.Commit()\n```\n\n#### Query rows\n\nConvenience functions `QueryRow` and `QueryRows` exist at the package level\nfor abstracting much of the boiler-plate code for reading rows. By supplying\na `ScanFunc`, you can fetch row(s) without managing most of the query logic.\n\n```go\nfunc example(id int) ([]*record, error) {\n  tx, done, xerr := db.StartRead(ctx)\n  if xerr != nil {\n    return nil, xerr\n  }\n  defer done()\n\n  const statement = `select * from mytable where id \u003e ?`\n\n  f := func(sf litesql.ScanFunc) (*record, error) {\n    r := new(record)\n    err := sf(\n      // \u0026r.field1\n      // \u0026r.field2\n      // ...\n    )\n    return r, err\n  }\n\n  return litesql.QueryRows(ctx, tx, f, statement, id)\n}\n```\n\n#### Execute statement\n\nThe `ExecID` and `Exec` statements are for write transactions. The `Exec`\nstatement needs to know how many rows to expect to be modified, returning an\nerror if expectations are not met. There are special package constants for\nindicating certain special cases. The `ExecID` method expects one row to be\nchanged, and will return the `ROWID` of the affected (or added) row.\n\n```go\nExpectAnything   // do not enforce any expecation on number of rows changed\nExpectNonZero    // at least one row must be changed\nExpectOneOrZero  // exactly 0 or 1 row must be changed, useful for upserts\nExpectOne        // exactly 1 row must be changed\nExpectNone       // exactly 0 rows must be changed\n```\n\nA simple update example.\n\n```go\nfunc example(id int, value string) error {\n  tx, done, xerr := db.StartWrite(ctx)\n  if xerr != nil {\n    return xerr\n  }\n  defer done()\n\n  const statement = `update mytable set v = ? where id = ?`\n\n  if err := db.Exec(ctx, tx, litesql.ExpectOneOrZero, statement, value, id); err != nil {\n    return err\n  }\n\n  return tx.Commit()\n}\n```\n\n#### Show pragma values\n\nIt is often helpful to dump the database pragma values on startup. This can\nbe done using the `Pragmas` method, which returns a `map[string]string` of\nmost common SQLite pragma configuration values.\n\n```go\nm, _ := db.Pragmas(ctx)\n\nfor k, v := range m {\n  fmt.Println(\"pragma\", k, \"value\", v)\n}\n```\n\n#### Creating a snapshot\n\nThe `Snapshot` method creates a point-in-time copy of the database, useful\nfor backups or creating read-only copies for sharing. Snapshots are copied\npage-by-page using SQLite's backup API, with configurable `Step` and `Gap`\noptions to control concurrency with writers.\n\n```go\nerr := db.Snapshot(\u0026litesql.SnapshotOptions{\n    Directory:  \"/path/to/snapshots\",        // where to write the snapshot\n    Retention:  3,                           // keep last 3 snapshots\n    Step:       100,                         // copy 100 pages per step\n    Gap:        1 * time.Millisecond,       // wait between steps\n    Progress: func(pages, remaining int) {\n        fmt.Printf(\"progress: %d/%d pages\\n\", pages-remaining, pages)\n    },\n})\n```\n\nThe snapshot files are named `snapshot-\u003ctimestamp\u003e.db` in the specified\ndirectory, and older files are automatically cleaned up according to the\n`Retention` policy.\n\n#### Sanitizing FTS5 queries\n\nSQLite FTS5 uses special control characters (`*`, `:`, `^`, `\"`, etc.) that can\ncause query errors or allow malicious query injection. Use `SanitizeFTS5` to\nstrip these characters before passing user input to an FTS5 query.\n\n```go\nquery := \"hello world*\"                  // prefix-operator performance implications\nsanitized := litesql.SanitizeFTS5(query) // removes fts5 control characters\nfmt.Println(sanitized)                   // \"hello world\"\n```\n\n### License\n\nThe `cattlecloud.net/go/litesql` module is opensource under the [BSD-3-Clause](LICENSE) license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcattlecloud%2Flitesql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcattlecloud%2Flitesql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcattlecloud%2Flitesql/lists"}