{"id":22075658,"url":"https://github.com/libsql/hrana-client-ts","last_synced_at":"2025-03-22T19:07:12.584Z","repository":{"id":94443563,"uuid":"608129861","full_name":"libsql/hrana-client-ts","owner":"libsql","description":"Hrana client for TypeScript and JavaScript","archived":false,"fork":false,"pushed_at":"2024-09-19T08:20:29.000Z","size":297,"stargazers_count":25,"open_issues_count":7,"forks_count":7,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-14T22:03:15.746Z","etag":null,"topics":["client","libsql","sqlite","typescript"],"latest_commit_sha":null,"homepage":"https://libsql.org/hrana-client-ts/","language":"TypeScript","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/libsql.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":"2023-03-01T11:37:21.000Z","updated_at":"2025-03-10T02:03:17.000Z","dependencies_parsed_at":"2024-01-26T09:32:22.680Z","dependency_job_id":"f272919a-c899-4037-afcb-e5ce5f934668","html_url":"https://github.com/libsql/hrana-client-ts","commit_stats":{"total_commits":24,"total_committers":1,"mean_commits":24.0,"dds":0.0,"last_synced_commit":"35015a84931cad50a8300c9c33dadcc38cc7254d"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libsql%2Fhrana-client-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libsql%2Fhrana-client-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libsql%2Fhrana-client-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libsql%2Fhrana-client-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libsql","download_url":"https://codeload.github.com/libsql/hrana-client-ts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245007240,"owners_count":20546143,"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":["client","libsql","sqlite","typescript"],"created_at":"2024-11-30T22:10:25.598Z","updated_at":"2025-03-22T19:07:12.555Z","avatar_url":"https://github.com/libsql.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hrana client for TypeScript\n\n**[API docs][docs] | [Github][github] | [npm][npm]**\n\n[docs]: https://libsql.org/hrana-client-ts/\n[github]: https://github.com/libsql/hrana-client-ts/\n[npm]: https://www.npmjs.com/package/@libsql/hrana-client\n\nThis package implements a Hrana client for TypeScript. Hrana is the protocol for connecting to sqld using WebSocket or HTTP.\n\n\u003e This package is intended mostly for internal use. Consider using the [`@libsql/client`][libsql-client] package, which will use Hrana automatically.\n\n[libsql-client]: https://www.npmjs.com/package/@libsql/client\n\n## Usage\n\n```typescript\nimport * as hrana from \"@libsql/hrana-client\";\n\n// Open a `hrana.Client`, which works like a connection pool in standard SQL\n// databases. \nconst url = process.env.URL ?? \"ws://localhost:8080\"; // Address of the sqld server\nconst jwt = process.env.JWT; // JWT token for authentication\n// Here we are using Hrana over WebSocket:\nconst client = hrana.openWs(url, jwt);\n// But we can also use Hrana over HTTP:\n// const client = hrana.openHttp(url, jwt);\n\n// Open a `hrana.Stream`, which is an interactive SQL stream. This corresponds\n// to a \"connection\" from other SQL databases\nconst stream = client.openStream();\n\n// Fetch all rows returned by a SQL statement\nconst books = await stream.query(\"SELECT title, year FROM book WHERE author = 'Jane Austen'\");\n// The rows are returned in an Array...\nfor (const book of books.rows) {\n    // every returned row works as an array (`book[1]`) and as an object (`book.year`)\n    console.log(`${book.title} from ${book.year}`);\n}\n\n// Fetch a single row\nconst book = await stream.queryRow(\"SELECT title, MIN(year) FROM book\");\nif (book.row !== undefined) {\n    console.log(`The oldest book is ${book.row.title} from year ${book.row[1]}`);\n}\n\n// Fetch a single value, using a bound parameter\nconst year = await stream.queryValue([\"SELECT MAX(year) FROM book WHERE author = ?\", [\"Jane Austen\"]]);\nif (year.value !== undefined) {\n    console.log(`Last book from Jane Austen was published in ${year.value}`);\n}\n\n// Execute a statement that does not return any rows\nconst res = await stream.run([\"DELETE FROM book WHERE author = ?\", [\"J. K. Rowling\"]])\nconsole.log(`${res.affectedRowCount} books have been cancelled`);\n\n// When you are done, remember to close the client\nclient.close();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibsql%2Fhrana-client-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibsql%2Fhrana-client-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibsql%2Fhrana-client-ts/lists"}