{"id":17753089,"url":"https://github.com/answerdotai/sqlite-minutils","last_synced_at":"2025-03-17T15:13:10.681Z","repository":{"id":243335748,"uuid":"812151295","full_name":"AnswerDotAI/sqlite-minutils","owner":"AnswerDotAI","description":"A fork of sqlite-utils with CLI etc removed","archived":false,"fork":false,"pushed_at":"2024-12-02T12:20:51.000Z","size":521,"stargazers_count":14,"open_issues_count":13,"forks_count":8,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-13T13:04:51.381Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://AnswerDotAI.github.io/sqlite-minutils","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AnswerDotAI.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2024-06-08T05:09:30.000Z","updated_at":"2025-02-01T19:02:00.000Z","dependencies_parsed_at":"2024-06-08T06:27:07.557Z","dependency_job_id":"bb0b084c-1a9b-48f4-b4c5-7cf35807d59b","html_url":"https://github.com/AnswerDotAI/sqlite-minutils","commit_stats":{"total_commits":38,"total_committers":8,"mean_commits":4.75,"dds":0.2894736842105263,"last_synced_commit":"ecc05929c9db9f7715c7624a95a3db383c78e75e"},"previous_names":["answerdotai/sqlite-minutils"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnswerDotAI%2Fsqlite-minutils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnswerDotAI%2Fsqlite-minutils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnswerDotAI%2Fsqlite-minutils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnswerDotAI%2Fsqlite-minutils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AnswerDotAI","download_url":"https://codeload.github.com/AnswerDotAI/sqlite-minutils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244056425,"owners_count":20390719,"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":[],"created_at":"2024-10-26T13:07:51.320Z","updated_at":"2025-03-17T15:13:10.659Z","avatar_url":"https://github.com/AnswerDotAI.png","language":"Python","readme":"# sqlite-minutils\n\n\n\u003c!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! --\u003e\n\n\u003e [!TIP]\n\u003e\n\u003e ### Where to find the complete documentation for this library\n\u003e\n\u003e If you want to learn about everything this project can do, we\n\u003e recommend reading the Python library section of the sqlite-utils\n\u003e project\n\u003e [here](https://sqlite-utils.datasette.io/en/stable/python-api.html).\n\u003e\n\u003e This project wouldn’t exist without Simon Willison and his excellent\n\u003e [sqlite-utils](https://github.com/simonw/sqlite-utils) project. Most\n\u003e of this project is his code, with some minor changes made to it.\n\n## Install\n\n    pip install sqlite-minutils\n\n## Use\n\nFirst, import the sqlite-miniutils library. Through the use of the\n**all** attribute in our Python modules by using `import *` we only\nbring in the `Database`, `Queryable`, `Table`, `View` classes. There’s\nno risk of namespace pollution.\n\n``` python\nfrom sqlite_minutils.db import *\n```\n\nThen we create a SQLite database. For the sake of convienance we’re\ndoing it in-memory with the `:memory:` special string. If you wanted\nsomething more persistent, name it something not surrounded by colons,\n`data.db` is a common file name.\n\n``` python\ndb = Database(\":memory:\")\n```\n\nLet’s drop (aka ‘delete’) any tables that might exist. These docs also\nserve as a test harness, and we want to make certain we are starting\nwith a clean slate. This also serves as a handy sneak preview of some of\nthe features of this library.\n\n``` python\nfor t in db.tables: t.drop()\n```\n\nUser tables are a handy way to create a useful example with some\nreal-world meaning. To do this, we first instantiate the `users` table\nobject:\n\n``` python\nusers = Table(db, 'Users')\nusers\n```\n\n    \u003cTable Users (does not exist yet)\u003e\n\nThe table doesn’t exist yet, so let’s add some columns via the\n`Table.create` method:\n\n``` python\nusers.create(columns=dict(id=int, name=str, age=int))\nusers\n```\n\n    \u003cTable Users (id, name, age)\u003e\n\nWhat if we need to change the table structure?\n\nFor example User tables often include things like password field. Let’s\nadd that now by calling `create` again, but this time with\n`transform=True`. We should now see that the `users` table now has the\n`pwd:str` field added.\n\n``` python\nusers.create(columns=dict(id=int, name=str, age=int, pwd=str), transform=True, pk='id')\nusers\n```\n\n    \u003cTable Users (id, name, age, pwd)\u003e\n\n``` python\nprint(db.schema)\n```\n\n    CREATE TABLE \"Users\" (\n       [id] INTEGER PRIMARY KEY,\n       [name] TEXT,\n       [age] INTEGER,\n       [pwd] TEXT\n    );\n\n## Queries\n\nLet’s add some users to query:\n\n``` python\nusers.insert(dict(name='Raven', age=8, pwd='s3cret'))\nusers.insert(dict(name='Magpie', age=5, pwd='supersecret'))\nusers.insert(dict(name='Crow', age=12, pwd='verysecret'))\nusers.insert(dict(name='Pigeon', age=3, pwd='keptsecret'))\nusers.insert(dict(name='Eagle', age=7, pwd='s3cr3t'))\n```\n\n    \u003cTable Users (id, name, age, pwd)\u003e\n\nA simple unfiltered select can be executed using `rows` property on the\ntable object.\n\n``` python\nusers.rows\n```\n\n    \u003cgenerator object Queryable.rows_where at 0x10849f6f0\u003e\n\nLet’s iterate over that generator to see the results:\n\n``` python\n[o for o in users.rows]\n```\n\n    [{'id': 1, 'name': 'Raven', 'age': 8, 'pwd': 's3cret'},\n     {'id': 2, 'name': 'Magpie', 'age': 5, 'pwd': 'supersecret'},\n     {'id': 3, 'name': 'Crow', 'age': 12, 'pwd': 'verysecret'},\n     {'id': 4, 'name': 'Pigeon', 'age': 3, 'pwd': 'keptsecret'},\n     {'id': 5, 'name': 'Eagle', 'age': 7, 'pwd': 's3cr3t'}]\n\nFiltering can be done via the `rows_where` function:\n\n``` python\n[o for o in users.rows_where('age \u003e 3')]\n```\n\n    [{'id': 1, 'name': 'Raven', 'age': 8, 'pwd': 's3cret'},\n     {'id': 2, 'name': 'Magpie', 'age': 5, 'pwd': 'supersecret'},\n     {'id': 3, 'name': 'Crow', 'age': 12, 'pwd': 'verysecret'},\n     {'id': 5, 'name': 'Eagle', 'age': 7, 'pwd': 's3cr3t'}]\n\nWe can also `limit` the results:\n\n``` python\n[o for o in users.rows_where('age \u003e 3', limit=2)]\n```\n\n    [{'id': 1, 'name': 'Raven', 'age': 8, 'pwd': 's3cret'},\n     {'id': 2, 'name': 'Magpie', 'age': 5, 'pwd': 'supersecret'}]\n\nThe `offset` keyword can be combined with the `limit` keyword.\n\n``` python\n[o for o in users.rows_where('age \u003e 3', limit=2, offset=1)]\n```\n\n    [{'id': 2, 'name': 'Magpie', 'age': 5, 'pwd': 'supersecret'},\n     {'id': 3, 'name': 'Crow', 'age': 12, 'pwd': 'verysecret'}]\n\nThe `offset` must be used with `limit` or raise a `ValueError`:\n\n``` python\ntry:\n    [o for o in users.rows_where(offset=1)]\nexcept ValueError as e:\n    print(e)\n```\n\n    Cannot use offset without limit\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanswerdotai%2Fsqlite-minutils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanswerdotai%2Fsqlite-minutils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanswerdotai%2Fsqlite-minutils/lists"}