{"id":17657973,"url":"https://github.com/3rd/sqlite.nvim","last_synced_at":"2025-05-07T10:34:14.133Z","repository":{"id":242289201,"uuid":"809174161","full_name":"3rd/sqlite.nvim","owner":"3rd","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-09T21:48:24.000Z","size":17,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-07T10:32:47.243Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Lua","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/3rd.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":"2024-06-01T23:09:12.000Z","updated_at":"2025-02-09T21:48:28.000Z","dependencies_parsed_at":"2024-06-02T00:30:31.145Z","dependency_job_id":"9c8cb17a-32c3-4ec9-92c6-cc4a0486d21e","html_url":"https://github.com/3rd/sqlite.nvim","commit_stats":null,"previous_names":["3rd/sqlite.nvim"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3rd%2Fsqlite.nvim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3rd%2Fsqlite.nvim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3rd%2Fsqlite.nvim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3rd%2Fsqlite.nvim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/3rd","download_url":"https://codeload.github.com/3rd/sqlite.nvim/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252860093,"owners_count":21815462,"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-23T14:43:49.653Z","updated_at":"2025-05-07T10:34:14.100Z","avatar_url":"https://github.com/3rd.png","language":"Lua","readme":"# sqlite.nvim\n\nLibrary for working with SQLite databases in Neovim.\n\\\nRequires `sqlite3` in `PATH`.\n\n### Usage - Database\n\n```lua\nlocal sqlite = require(\"sqlite\")\n\n-- open and close a database\nlocal db = sqlite.open(\"test.db\") -- or \":memory:\"\ndb:close()\n\n-- execute commands with db:exec         command   raw (don't parse as JSON)\nlocal result = db:exec(\"SELECT sqlite_version();\", false)\n-- or with db:sql (appends \";\", parses JSON)\nlocal result = db:sql(\"SELECT sqlite_version()\")\n\n-- create a table\ndb:sql(\"CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT NOT NULL)\")\n-- or\ndb:execute(\"CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT NOT NULL);\")\n-- or\ndb:create_table(\"users\", {\n    \"id INTEGER PRIMARY KEY\",\n    \"name TEXT NOT NULL\",\n})\n\n-- insert a record\ndb:sql(\"INSERT INTO users (id, name) VALUES (1, 'John Doe')\")\n-- or\ndb:insert(\"users\", { id = 1, name = \"John Doe\" })\n\n-- fetch records\nlocal users = db:sql(\"SELECT * FROM users WHERE name = 'John Doe'\")\n-- or\nlocal users = db:select(\"users\", \"name = 'John Doe'\", \"*\")\n\n-- update a record\ndb:sql(\"UPDATE users SET name = 'Jane Doe' WHERE id = 1\")\n-- or\ndb:update(\"users\", \"id = 1\", { name = \"Jane Doe\" })\n\n-- delete a record\ndb:sql(\"DELETE FROM users WHERE id = 1\")\n-- or\ndb:delete(\"users\", \"id = 1\")\n\n-- drop a table\ndb:sql(\"DROP TABLE users\")\n-- or\ndb:drop_table(\"users\")\n\n-- get tables and columns\nlocal tables = db:get_tables()\nlocal columns = db:get_columns(\"users\")\n```\n\n### Usage - ORM\n\nThe plugin also provides a tiny ORM that you might find useful.\n\n```lua\nlocal orm = require(\"sqlite.orm\")\n\n-- define a model\nlocal User = orm.define(\"users\", {\n  id = orm.integer({ primary_key = true, auto_increment = true }),\n  name = orm.text({ not_null = true }),\n  email = orm.text({ unique = true }),\n  age = orm.integer(),\n})\n\n-- connect to a database\nUser:connect(\":memory:\")\n\n-- create a new record\nlocal id = User:create({ name = \"John Doe\", email = \"john@example.com\", age = 30 })\n\n-- read records\nlocal users = User:all()\nlocal users = User:find(\"age \u003c 30\")\nlocal user = User:find_by_id(1)\nlocal user = User:find_one(\"name = 'John Doe'\")\n\n-- update a record\nUser:update(\"id = \" .. id, { age = 36 })\n\n-- delete a record\nUser:delete(\"id = \" .. id)\n\n-- query builder\nlocal young_users = User:query():select({ \"name\", \"age\" }):where(\"age \u003c 50\"):order_by(\"age DESC\"):limit(1):execute()\n```\n\n### API\n\n#### Database\n\nWhen you execute `sqlite.open(\"test.db\")`, a new `sqlite3` process is spawned and you get back a `Database` object.\n\n| Method                                       | Description                                                                               |\n| -------------------------------------------- | ----------------------------------------------------------------------------------------- |\n| `db:open(path, options)`                     | Opens a new database connection, options defaults to `{ debug = false, timeout = 5000 }`. |\n| `db:close()`                                 | Closes the database connection.                                                           |\n| `db:exec(command, raw?)`                     | Executes a command and returns the output as a `table`, `string` or `nil`.                |\n| `db:sql(command)`                            | Like `Database:exec`, but ensures trailing `;` and JSON parsing.                          |\n| `db:get_tables()`                            | Returns a list of tables.                                                                 |\n| `db:get_columns(tableName)`                  | Returns a list of columns for a table.                                                    |\n| `db:create_table(tableName, columns)`        | Syntactic sugar for creating a table.                                                     |\n| `db:drop_table(tableName)`                   | Syntactic sugar for dropping a table.                                                     |\n| `db:insert(tableName, data)`                 | Syntactic sugar for inserting a record.                                                   |\n| `db:select(tableName, condition?, columns?)` | Syntactic sugar for selecting records.                                                    |\n| `db:update(tableName, condition?, data)`     | Syntactic sugar for updating records.                                                     |\n| `db:delete(tableName, condition?)`           | Syntactic sugar for deleting records.                                                     |\n\n#### ORM\n\n| Method                                   | Description                                       |\n| ---------------------------------------- | ------------------------------------------------- |\n| `orm.define(name, schema)`               | Defines a new model.                              |\n| `orm.integer(opts?)`                     | Helper for defining an integer field.             |\n| `orm.text(opts?)`                        | Helper for defining a text field.                 |\n| `orm.real(opts?)`                        | Helper for defining a real field.                 |\n| `model:connect(db_or_path, db_options?)` | Connects the model to a database.                 |\n| `model:get_primary_keys()`               | Returns the primary keys for the model.           |\n| `model:create(data)`                     | Creates a new record.                             |\n| `model:find(condition?)`                 | Finds records.                                    |\n| `model:find_one(condition?)`             | Finds a single record.                            |\n| `model:find_by_id(id)`                   | Finds a record by its ID (must have a single PK). |\n| `model:all()`                            | Gets all records.                                 |\n| `model:update(condition?, data)`         | Updates records.                                  |\n| `model:delete(condition?)`               | Deletes records.                                  |\n| `model:query()`                          | Returns a query builder.                          |\n| `query:select(fields?)`                  | Selects specific fields.                          |\n| `query:where(condition?)`                | Filters records with a condition.                 |\n| `query:order_by(fields?)`                | Orders records by a field.                        |\n| `query:limit(n)`                         | Limits the number of records returned.            |\n| `query:execute()`                        | Executes the query and returns the result.        |\n\n### Development\n\n```sh\ngit clone --recurse-submodules https://github.com/3rd/sqlite.nvim\ncd sqlite.nvim\nmake # you'll see all the available commands\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3rd%2Fsqlite.nvim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F3rd%2Fsqlite.nvim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3rd%2Fsqlite.nvim/lists"}