{"id":38256214,"url":"https://github.com/dir01/litestore","last_synced_at":"2026-01-17T01:31:49.519Z","repository":{"id":311270636,"uuid":"1022309993","full_name":"dir01/litestore","owner":"dir01","description":"sqlite-based schemaless typesafe storage","archived":false,"fork":false,"pushed_at":"2025-12-13T07:53:02.000Z","size":91,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-12-14T11:02:40.681Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dir01.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2025-07-18T20:24:36.000Z","updated_at":"2025-12-13T07:52:17.000Z","dependencies_parsed_at":"2025-08-23T18:22:23.384Z","dependency_job_id":"632e3df3-4dd4-473a-a548-bdf18676d886","html_url":"https://github.com/dir01/litestore","commit_stats":null,"previous_names":["dir01/litestore"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dir01/litestore","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dir01%2Flitestore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dir01%2Flitestore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dir01%2Flitestore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dir01%2Flitestore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dir01","download_url":"https://codeload.github.com/dir01/litestore/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dir01%2Flitestore/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28491585,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T00:50:05.742Z","status":"ssl_error","status_checked_at":"2026-01-17T00:43:11.982Z","response_time":107,"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":[],"created_at":"2026-01-17T01:31:49.419Z","updated_at":"2026-01-17T01:31:49.494Z","avatar_url":"https://github.com/dir01.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# litestore\n\n`litestore` is a lightweight, schemaless, and typesafe storage layer for Go, built on top of SQLite. It provides a simple and intuitive API for persisting Go structs as JSON data, without the complexity of a full-featured ORM.\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/dir01/litestore.svg)](https://pkg.go.dev/github.com/dir01/litestore)\n\n## Key Features\n\n*   **Schemaless \u0026 Typesafe**: Store your Go structs directly without defining a schema, while still benefiting from Go's type safety.\n*   **Simple API**: A minimal and opinionated API for common CRUD operations.\n*   **Flexible Querying**: Build complex queries using a simple and composable predicate system.\n*   **Transactional Support**: Execute multiple operations in a single, atomic transaction.\n*   **Self-Contained**: The entire database is a single file on disk (thanks to SQLite), making it perfect for simple applications, command-line tools, and prototypes.\n\n## Getting Started\n\nFirst, add `litestore` to your project:\n\n```sh\ngo get github.com/dir01/litestore\n```\n\nNext, you can use `litestore` to save and retrieve your Go structs:\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"database/sql\"\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com/dir01/litestore\"\n\t_ \"github.com/mattn/go-sqlite3\" // SQLite driver\n)\n\n// User represents a user in our system.\ntype User struct {\n\tID    string `litestore:\"key\"`\n\tName  string `json:\"name\"`\n\tEmail string `json:\"email\"`\n}\n\nfunc main() {\n\t// Open the SQLite database.\n\tdb, err := sql.Open(\"sqlite3\", \"example.db\")\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to open database: %v\", err)\n\t}\n\tdefer db.Close()\n\n\tctx := context.Background()\n\n\t// Create a store for User entities.\n\tuserStore, err := litestore.NewStore[User](ctx, db, \"users\")\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to create user store: %v\", err)\n\t}\n\tdefer userStore.Close()\n\n\t// --- Create a new user ---\n\tnewUser := \u0026User{\n\t\tName:  \"Alice\",\n\t\tEmail: \"alice@example.com\",\n\t}\n\tif err := userStore.Save(ctx, newUser); err != nil {\n\t\tlog.Fatalf(\"failed to save user: %v\", err)\n\t}\n\tfmt.Printf(\"Saved user '%s' with ID: %s\\n\", newUser.Name, newUser.ID)\n\n\t// --- Retrieve a user by their email ---\n\tretrievedUser, err := userStore.GetOne(ctx, litestore.Filter{Key: \"email\", Op: litestore.OpEq, Value: \"alice@example.com\"})\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to get user by email: %v\", err)\n\t}\n\tfmt.Printf(\"Retrieved user: %s (%s)\\n\", retrievedUser.Name, retrievedUser.Email)\n\n\t// --- Delete the user ---\n\tif err := userStore.Delete(ctx, retrievedUser.ID); err != nil {\n\t\tlog.Fatalf(\"failed to delete user: %v\", err)\n\t}\n\tfmt.Println(\"User deleted successfully.\")\n}\n```\n\n## Querying\n\n`litestore` provides a flexible querying system that allows you to build complex queries using a simple and composable predicate system.\n\n### Filters\n\nA `Filter` represents a single condition in a query. For example, to find all users with the name \"Alice\", you would use the following filter:\n\n```go\nlitestore.Filter{Key: \"name\", Op: litestore.OpEq, Value: \"Alice\"}\n```\n\n### Combining Predicates\n\nYou can combine multiple predicates using `AndPredicates` and `OrPredicates` to create more complex queries. For example, to find all users with the name \"Alice\" who are also active, you would use the following query:\n\n```go\nlitestore.AndPredicates(\n\tlitestore.Filter{Key: \"name\", Op: litestore.OpEq, Value: \"Alice\"},\n\tlitestore.Filter{Key: \"is_active\", Op: litestore.OpEq, Value: true},\n)\n```\n\n### Iterating over Results\n\nYou can iterate over the results of a query using the `Iter` method. It returns a Go 1.22 `iter.Seq2` iterator. A `nil` query can be used to iterate over all entities.\n\n```go\n// Iterate over all users\nseq, err := userStore.Iter(ctx, nil)\nif err != nil {\n\tlog.Fatalf(\"failed to create iterator: %v\", err)\n}\n\nfor user, err := range seq {\n\tif err != nil {\n\t\tlog.Fatalf(\"iteration failed: %v\", err)\n\t}\n\tfmt.Printf(\"Found user: %s\\n\", user.Name)\n}\n```\n\n### Ordering and Limiting\n\nYou can also order and limit your query results using the `OrderBy` and `Limit` fields of the `Query` struct.\n\n```go\nq := \u0026litestore.Query{\n\tPredicate: litestore.Filter{Key: \"category\", Op: litestore.OpEq, Value: \"A\"},\n\tOrderBy: []litestore.OrderBy{\n\t\t{Key: \"value\", Direction: litestore.OrderDesc},\n\t},\n\tLimit: 10,\n}\n```\n\n## Transactions\n\n`litestore` supports transactions, allowing you to execute multiple operations in a single, atomic transaction. The `WithTransaction` function provides a simple and convenient way to work with transactions:\n\n```go\nerr = litestore.WithTransaction(ctx, db, func(txCtx context.Context) error {\n\t// Create a new user\n\tbob := \u0026User{Name: \"Bob\", Email: \"bob@example.com\"}\n\tif err := userStore.Save(txCtx, bob); err != nil {\n\t\treturn fmt.Errorf(\"failed to save bob in tx: %w\", err)\n\t}\n\n\t// If this function returns an error, the transaction will be rolled back.\n\t// If it returns nil, it will be committed.\n\treturn nil\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdir01%2Flitestore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdir01%2Flitestore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdir01%2Flitestore/lists"}