{"id":13693897,"url":"https://github.com/alicebob/sqlittle","last_synced_at":"2025-05-16T05:06:21.668Z","repository":{"id":43642598,"uuid":"127201711","full_name":"alicebob/sqlittle","owner":"alicebob","description":"Pure Go SQLite file reader ","archived":false,"fork":false,"pushed_at":"2023-02-28T08:43:53.000Z","size":622,"stargazers_count":199,"open_issues_count":1,"forks_count":12,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-14T14:13:40.030Z","etag":null,"topics":["go","pure-go","sqlite","sqlite3"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alicebob.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}},"created_at":"2018-03-28T21:39:18.000Z","updated_at":"2025-01-31T11:27:06.000Z","dependencies_parsed_at":"2024-01-13T22:55:38.424Z","dependency_job_id":"fce48d2e-e293-4e7c-9499-84781339f38d","html_url":"https://github.com/alicebob/sqlittle","commit_stats":null,"previous_names":["alicebob/sqlit"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alicebob%2Fsqlittle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alicebob%2Fsqlittle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alicebob%2Fsqlittle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alicebob%2Fsqlittle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alicebob","download_url":"https://codeload.github.com/alicebob/sqlittle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254471061,"owners_count":22076585,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["go","pure-go","sqlite","sqlite3"],"created_at":"2024-08-02T17:01:19.980Z","updated_at":"2025-05-16T05:06:16.659Z","avatar_url":"https://github.com/alicebob.png","language":"Go","readme":"Package SQLittle provides pure Go, read-only, access to SQLite (version 3) database\nfiles.\n\n## What\nSQLittle reads SQLite3 tables and indexes. It iterates over tables, and\ncan search efficiently using indexes. SQLittle will deal with all SQLite\nstorage quirks, but otherwise it doesn't try to be smart; if you want to use\nan index you have to give the name of the index.\n\nThere is no support for SQL, and if you want to do the most efficient joins\npossible you'll have to use the low level code.\n\nBased on https://sqlite.org/fileformat2.html and some SQLite source code reading.\n\n## Why\nThis whole thing is mostly for fun. The normal SQLite libraries are perfectly great, and\nthere is no real need for this. However, since this library is pure Go\ncross-compilation is much easier. Given the constraints a valid use-case would\nfor example be storing app configuration in read-only sqlite files.\n\n## Docs\nhttps://godoc.org/github.com/alicebob/sqlittle for the go doc and examples.\n\nSee [LOWLEVEL.md](LOWLEVEL.md) about the low level reader.\nSee [CODE.md](CODE.md) for an overview how the code is structured.\n\n## Features\nThings SQLittle can do:\n\n```\n- table scan in row order; table scan in index order; simple searches with use of (partial) indexes\n- works on both rowid and non-rowid (`WITHOUT ROWID`) tables\n- files can be used concurrently with sqlite (compatible locks)\n- behaves nicely on corrupted database files (no panics)\n- detects corrupt journal files\n- hides all SQLite low level storage details\n- DESC indexes are handled automatically\n- Collate functions are used automatically\n- indexes with expression (either in columns or as a `WHERE`) are (partially) supported\n- Scan() to most Go datatypes, including `time.Time`\n- works on Linux, Mac OS, and Windows\n- has an experimental database/sql driver, see below\n```\n\nThings SQLittle should do:\n\n```\n- add a helper to find indexes. That would be especially useful for the `sqlite_autoindex_...` indexes\n- optimize loading when all requested columns are available in the index\n- expose the locking so you can do bigger read transactions\n```\n\nThings SQLittle can not do:\n\n```\n- read-only\n- only supports UTF8 strings\n- no joins\n- WAL files are not supported\n- indexes are used for sorting, but there is no on-the-fly sorting\n```\n\n## Locks\nSQLittle has a read-lock on the file during the whole execution of the\nselect-like functions. It's safe to update the database using SQLite while the\nfile is opened in SQLittle.\n\n## Status\nThe current level of abstraction is likely the final one (that is: deal\nwith reading single tables; don't even try joins or SQL or query planning), but\nthe API might still change.\n\n\n\n# Examples\n\n## Basic SELECT\nCode:\n\n```\n{\n\tdb, err := sqlittle.Open(\"./testdata/music.sqlite\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer db.Close()\n\tdb.Select(\"tracks\", func(r sqlittle.Row) {\n\t\tvar (\n\t\t\tname   string\n\t\t\tlength int\n\t\t)\n\t\t_ = r.Scan(\u0026name, \u0026length)\n\t\tfmt.Printf(\"%s: %d seconds\\n\", name, length)\n\t}, \"name\", \"length\")\n}\n```\nOutput:\n\n```\nDrive My Car: 145 seconds\nNorwegian Wood: 121 seconds\nYou Wont See Me: 198 seconds\nCome Together: 259 seconds\nSomething: 182 seconds\nMaxwells Silver Hammer: 207 seconds\n\n```\n\n\n\n## SELECT by primary key\nCode:\n\n```\n{\n\tdb, err := sqlittle.Open(\"./testdata/music.sqlite\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer db.Close()\n\tdb.PKSelect(\"tracks\", sqlittle.Key{4}, func(r sqlittle.Row) {\n\t\tname, _ := r.ScanString()\n\t\tfmt.Printf(\"%s\\n\", name)\n\t}, \"name\")\n}\n```\nOutput:\n\n```\nCome Together\n\n```\n\n\n# Driver\n\nThe ./driver/ package implements an *experimental* driver for `database/sql`. It currently supports very basic SELECT statements only. Issues, PRs, and feature requests are (as always) welcome.\n\n## Idea\n\nThe driver exposes sqlittle as a `database/sql` driver. It uses the main sqlittle package to implement a basic query executor, which can be used as any other Go database driver.\n\nIt will never support full SQL, but certain things we can do without implementing an actual database system. For example `ORDER BY` could be supported, as long as you have an index which we can use for it. `LIMIT` should be easy. But `GROUP BY` needs an actual database system, so that's out.\n\n## Supported SQL\n\nThese statements are supported. Anything else is not:\n\n- `SELECT * FROM yourtable`\n- `SELECT col1, col2 FROM yourtable`\n\n## example\n\n```\nimport (\n\t\"database/sql\"\n\n\t_ \"github.com/alicebob/sqlittle/driver\"\n)\n\nfunc Albums() {\n\tc, err := sql.Open(\"sqlittle\", \"../testdata/music.sqlite\")\n\trows, err := c.Query(`SELECT * FROM albums`)\n\t// normal rows.Next() stuff\n\t// Be sure to check rows.Err()!\n}\n```\n\n\n# \u0026c.\n\n[![GoDoc](https://pkg.go.dev/badge/github.com/alicebob/sqlittle)](https://pkg.go.dev/github.com/alicebob/sqlittle)\n[![Build Status](https://travis-ci.com/alicebob/sqlittle.png?branch=master)](https://travis-ci.com/alicebob/sqlittle)\n\n`make fuzz` uses [go-fuzz](https://github.com/dvyukov/go-fuzz)\n\nSee [sqlite2go](https://github.com/cznic/sqlite2go/) for another approach to pure Go SQLite\n","funding_links":[],"categories":["开源类库","Open source library"],"sub_categories":["数据库","Database"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falicebob%2Fsqlittle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falicebob%2Fsqlittle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falicebob%2Fsqlittle/lists"}