# @libsql/hrana-client

> Hrana client for connecting to sqld over HTTP or WebSocket

Latest version **0.10.0** (published 2026-04-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install @libsql/hrana-client
pnpm add @libsql/hrana-client
yarn add @libsql/hrana-client
bun add @libsql/hrana-client
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.10.0 |
| Published | 2026-04-22 |
| First published | 2023-03-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 298.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 28 |
| Maintainers | penberg |
| Keywords | hrana, libsql, sqld, database |

## Links

- npm: https://www.npmjs.com/package/@libsql/hrana-client
- Repository: https://github.com/libsql/hrana-client-ts
- Issues: https://github.com/libsql/hrana-client-ts/issues
- npm.io page: https://npm.io/package/@libsql/hrana-client

## Dependencies (2)

- [js-base64](https://npm.io/package/js-base64.md) ^3.7.5
- [@libsql/isomorphic-ws](https://npm.io/package/@libsql/isomorphic-ws.md) ^0.1.5

## Alternatives

- [@libsql/sqlite3](https://npm.io/package/@libsql/sqlite3.md) — 39.8K weekly downloads
- [@fortemi/core](https://npm.io/package/@fortemi/core.md) — 461 weekly downloads
- [cdb-converter](https://npm.io/package/cdb-converter.md) — 341 weekly downloads
- [@uplo/adapter-prisma](https://npm.io/package/@uplo/adapter-prisma.md) — 75 weekly downloads
- [typeorm-aios](https://npm.io/package/typeorm-aios.md) — 30 weekly downloads

## Recent versions

- 0.10.0 (latest) — 2026-04-22
- 0.9.0 — 2025-12-26
- 0.8.0 — 2024-09-19
- 0.7.0 — 2024-09-16
- 0.6.2 — 2024-06-03
- 0.6.1 — 2024-06-03
- 0.6.0 — 2024-03-28
- 0.5.6 — 2024-01-26
- 0.5.5 — 2023-09-18
- 0.5.4 — 2023-09-18
- 0.5.3 — 2023-09-18
- 0.5.2 — 2023-09-11
- 0.5.1 — 2023-09-11
- 0.5.0 — 2023-08-29
- 0.5.0-pre.2 — 2023-08-23
- … 28 more at https://npm.io/package/@libsql/hrana-client/versions

## README

# Hrana client for TypeScript

**[API docs][docs] | [Github][github] | [npm][npm]**

[docs]: https://libsql.org/hrana-client-ts/
[github]: https://github.com/libsql/hrana-client-ts/
[npm]: https://www.npmjs.com/package/@libsql/hrana-client

This package implements a Hrana client for TypeScript. Hrana is the protocol for connecting to sqld using WebSocket or HTTP.

> This package is intended mostly for internal use. Consider using the [`@libsql/client`][libsql-client] package, which will use Hrana automatically.

[libsql-client]: https://www.npmjs.com/package/@libsql/client

## Usage

```typescript
import * as hrana from "@libsql/hrana-client";

// Open a `hrana.Client`, which works like a connection pool in standard SQL
// databases. 
const url = process.env.URL ?? "ws://localhost:8080"; // Address of the sqld server
const jwt = process.env.JWT; // JWT token for authentication
// Here we are using Hrana over WebSocket:
const client = hrana.openWs(url, jwt);
// But we can also use Hrana over HTTP:
// const client = hrana.openHttp(url, jwt);

// Open a `hrana.Stream`, which is an interactive SQL stream. This corresponds
// to a "connection" from other SQL databases
const stream = client.openStream();

// Fetch all rows returned by a SQL statement
const books = await stream.query("SELECT title, year FROM book WHERE author = 'Jane Austen'");
// The rows are returned in an Array...
for (const book of books.rows) {
    // every returned row works as an array (`book[1]`) and as an object (`book.year`)
    console.log(`${book.title} from ${book.year}`);
}

// Fetch a single row
const book = await stream.queryRow("SELECT title, MIN(year) FROM book");
if (book.row !== undefined) {
    console.log(`The oldest book is ${book.row.title} from year ${book.row[1]}`);
}

// Fetch a single value, using a bound parameter
const year = await stream.queryValue(["SELECT MAX(year) FROM book WHERE author = ?", ["Jane Austen"]]);
if (year.value !== undefined) {
    console.log(`Last book from Jane Austen was published in ${year.value}`);
}

// Execute a statement that does not return any rows
const res = await stream.run(["DELETE FROM book WHERE author = ?", ["J. K. Rowling"]])
console.log(`${res.affectedRowCount} books have been cancelled`);

// When you are done, remember to close the client
client.close();
```

---
_Source: https://npm.io/package/@libsql/hrana-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
