{"id":21332548,"url":"https://github.com/notrab/libsql-middleware","last_synced_at":"2025-07-12T10:31:41.325Z","repository":{"id":221397887,"uuid":"754263951","full_name":"notrab/libsql-middleware","owner":"notrab","description":"Middleware for @libsql/client","archived":false,"fork":false,"pushed_at":"2024-09-27T18:20:20.000Z","size":450,"stargazers_count":8,"open_issues_count":10,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-09-28T14:05:30.190Z","etag":null,"topics":["libsql","sqlite","turso"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/notrab.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}},"created_at":"2024-02-07T18:02:34.000Z","updated_at":"2024-09-21T20:51:26.000Z","dependencies_parsed_at":"2024-06-02T12:46:16.194Z","dependency_job_id":"4a03e1a0-efb1-4308-b19c-175189a96afe","html_url":"https://github.com/notrab/libsql-middleware","commit_stats":null,"previous_names":["notrab/libsql-client-hooks"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notrab%2Flibsql-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notrab%2Flibsql-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notrab%2Flibsql-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notrab%2Flibsql-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/notrab","download_url":"https://codeload.github.com/notrab/libsql-middleware/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225814861,"owners_count":17528295,"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":["libsql","sqlite","turso"],"created_at":"2024-11-21T22:52:18.169Z","updated_at":"2024-11-21T22:52:18.582Z","avatar_url":"https://github.com/notrab.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libsql-middleware\n\nThe middleware wrapper for `@libsql/client`.\n\n![NPM](https://img.shields.io/npm/v/libsql-middleware)\n\n## Install\n\n```bash\nnpm install libsql-middleware\n```\n\nMake sure to install `@libsql/client` if you don't already have it.\n\n## Quickstart\n\n```ts\nimport { createClient } from \"@libsql/client\";\nimport { beforeExecute, withMiddleware } from \"libsql-middleware\";\n\nconst client = createClient({ url: \"file:dev.db\" });\n\nconst logBeforeExecute = beforeExecute((query) =\u003e {\n  console.log(\"Before executing\");\n  return query;\n});\n\nconst clientWithHooks = withMiddleware(client, [logBeforeExecute]);\n\nawait clientWithHooks.execute(\n  \"CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)\"\n);\nawait clientWithHooks.execute(\"INSERT INTO users (name) VALUES ('Test User')\");\nawait clientWithHooks.execute(\"SELECT * FROM users\");\n```\n\n## API Reference\n\n### `beforeExecute`\n\n```ts\nimport { beforeExecute } from \"libsql-middleware\";\n\nconst logBeforeExecute = beforeExecute((query) =\u003e {\n  // Do something\n  return query;\n});\n```\n\n### `afterExecute`\n\n```ts\nimport { afterExecute } from \"libsql-middleware\";\n\nconst logAfterExecute = afterExecute((result, query) =\u003e {\n  // Do something\n  return result;\n});\n```\n\n### `beforeBatch`\n\n```ts\nimport { beforeBatch } from \"libsql-middleware\";\n\nconst logBeforeBatch = beforeBatch((stmts) =\u003e {\n  // Do something\n  return stmts;\n});\n```\n\n### `afterBatch`\n\n```ts\nimport { afterBatch } from \"libsql-middleware\";\n\nconst logAfterBatch = afterBatch((results, stmts) =\u003e {\n  // Do something\n  return results;\n});\n```\n\n### `withMiddleware`\n\nThe `withMiddleware` method binds the original `@libsql/client` methods so you can use them as you normally would, but now with middleware.\n\n```ts\nimport { withMiddleware } from \"libsql-middleware\";\n\nconst clientWithHooks = withMiddleware(client, [\n  // Your plugins\n]);\n\n// Use the `@libsql/client` as you normally would\n// But now with middleware!\nawait clientWithHooks.execute();\nawait clientWithHooks.batch();\nawait clientWithHooks.transaction();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotrab%2Flibsql-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnotrab%2Flibsql-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotrab%2Flibsql-middleware/lists"}