|
1 | 1 | <p align="center">
|
2 |
| - <a href="https://docs.turso.tech/sdk/ts/quickstart"> |
3 |
| - <img alt="Turso + TypeScript" src="https://github.com/tursodatabase/libsql-client-ts/assets/950181/5d3a2693-75f9-4c56-9107-8ccaa96785fd" width="1000"> |
4 |
| - <h3 align="center">Turso + TypeScript / JS</h3> |
| 2 | + <a href="https://tur.so/turso-ts"> |
| 3 | + <picture> |
| 4 | + <img src="/.github/cover.png" alt="libSQL TypeScript" /> |
| 5 | + </picture> |
5 | 6 | </a>
|
| 7 | + <h1 align="center">libSQL TypeScript</h1> |
6 | 8 | </p>
|
7 | 9 |
|
8 | 10 | <p align="center">
|
9 |
| - SQLite for Production. Powered by <a href="https://turso.tech/libsql">libSQL</a>. |
| 11 | + Databases for all TypeScript and JS multi-tenant apps. |
10 | 12 | </p>
|
11 | 13 |
|
12 | 14 | <p align="center">
|
13 |
| - <a href="https://turso.tech"><strong>Turso</strong></a> · |
14 |
| - <a href="https://docs.turso.tech/quickstart"><strong>Quickstart</strong></a> · |
15 |
| - <a href="/examples"><strong>Examples</strong></a> · |
| 15 | + <a href="https://tur.so/turso-ts"><strong>Turso</strong></a> · |
16 | 16 | <a href="https://docs.turso.tech"><strong>Docs</strong></a> ·
|
17 |
| - <a href="https://discord.com/invite/4B5D7hYwub"><strong>Discord</strong></a> · |
18 |
| - <a href="https://blog.turso.tech/"><strong>Blog & Tutorials</strong></a> |
| 17 | + <a href="https://docs.turso.tech/sdk/ts/quickstart"><strong>Quickstart</strong></a> · |
| 18 | + <a href="https://docs.turso.tech/sdk/ts/reference"><strong>SDK Reference</strong></a> · |
| 19 | + <a href="https://turso.tech/blog"><strong>Blog & Tutorials</strong></a> |
19 | 20 | </p>
|
20 | 21 |
|
21 | 22 | <p align="center">
|
22 |
| - <a href="https://www.npmjs.com/@libsql/client"> |
23 |
| - <img src="https://badge.fury.io/js/@libsql%2Fclient.svg" alt="npm version" title="npm version" /> |
| 23 | + <a href="LICENSE"> |
| 24 | + <picture> |
| 25 | + <img src="https://img.shields.io/github/license/tursodatabase/libsql-client-ts?color=0F624B" alt="MIT License" /> |
| 26 | + </picture> |
24 | 27 | </a>
|
25 |
| - <a href="https://discord.com/invite/4B5D7hYwub"> |
26 |
| - <img src="https://dcbadge.vercel.app/api/server/4B5D7hYwub?style=flat" alt="discord activity" title="join us on discord" /> |
| 28 | + <a href="https://tur.so/discord-ts"> |
| 29 | + <picture> |
| 30 | + <img src="https://img.shields.io/discord/933071162680958986?color=0F624B" alt="Discord" /> |
| 31 | + </picture> |
27 | 32 | </a>
|
28 |
| - <a href="https://www.phorm.ai/query?projectId=3c9a471f-4a47-469f-81f6-4ea1ff9ab418"><img src="https://img.shields.io/badge/Phorm-Ask_AI-%23F2777A.svg?&logo=data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNSIgaGVpZ2h0PSI0IiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgogIDxwYXRoIGQ9Ik00LjQzIDEuODgyYTEuNDQgMS40NCAwIDAgMS0uMDk4LjQyNmMtLjA1LjEyMy0uMTE1LjIzLS4xOTIuMzIyLS4wNzUuMDktLjE2LjE2NS0uMjU1LjIyNmExLjM1MyAxLjM1MyAwIDAgMS0uNTk1LjIxMmMtLjA5OS4wMTItLjE5Mi4wMTQtLjI3OS4wMDZsLTEuNTkzLS4xNHYtLjQwNmgxLjY1OGMuMDkuMDAxLjE3LS4xNjkuMjQ2LS4xOTFhLjYwMy42MDMgMCAwIDAgLjItLjEwNi41MjkuNTI5IDAgMCAwIC4xMzgtLjE3LjY1NC42NTQgMCAwIDAgLjA2NS0uMjRsLjAyOC0uMzJhLjkzLjkzIDAgMCAwLS4wMzYtLjI0OS41NjcuNTY3IDAgMCAwLS4xMDMtLjIuNTAyLjUwMiAwIDAgMC0uMTY4LS4xMzguNjA4LjYwOCAwIDAgMC0uMjQtLjA2N0wyLjQzNy43MjkgMS42MjUuNjcxYS4zMjIuMzIyIDAgMC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4NmEuOTcuOTcgMCAwIDEgLjMzOC0uMTRDMS4xMjIuMTIgMS4yMy4xMSAxLjMyOC4xMTlsMS41OTMuMTRjLjE2LjAxNC4zLjA0Ny40MjMuMWExLjE3IDEuMTcgMCAwIDEgLjU0NS40NDhjLjA2MS4wOTUuMTA5LjE5My4xNDQuMjk1YTEuNDA2IDEuNDA2IDAgMCAxIC4wNzcuNTgzbC0uMDI4LjMyMloiIGZpbGw9IndoaXRlIi8+Cjwvc3ZnPgo=" alt="phorm.ai"> |
| 33 | + <a href="#contributors"> |
| 34 | + <picture> |
| 35 | + <img src="https://img.shields.io/github/contributors/tursodatabase/libsql-client-ts?color=0F624B" alt="Contributors" /> |
| 36 | + </picture> |
| 37 | + </a> |
| 38 | + <a href="https://packagist.org/packages/turso/libsql"> |
| 39 | + <picture> |
| 40 | + <img src="https://img.shields.io/packagist/dt/turso/libsql?color=0F624B" alt="Total downloads" /> |
| 41 | + </picture> |
| 42 | + </a> |
| 43 | + <a href="/examples"> |
| 44 | + <picture> |
| 45 | + <img src="https://img.shields.io/badge/browse-examples-0F624B" alt="Examples" /> |
| 46 | + </picture> |
29 | 47 | </a>
|
30 | 48 | </p>
|
31 | 49 |
|
32 |
| ---- |
| 50 | +## Features |
| 51 | + |
| 52 | +- 🔌 Works offline with [Embedded Replicas](https://docs.turso.tech/features/embedded-replicas/introduction) |
| 53 | +- 🌎 Works with remote Turso databases |
| 54 | +- ✨ Works with Turso [AI & Vector Search](https://docs.turso.tech/features/ai-and-embeddings) |
| 55 | +- 🔐 Supports [encryption at rest](https://docs.turso.tech/libsql#encryption-at-rest) |
| 56 | + |
| 57 | +## Install |
| 58 | + |
| 59 | +```bash |
| 60 | +npm install @libsql/client |
| 61 | +``` |
| 62 | + |
| 63 | +## Quickstart |
| 64 | + |
| 65 | +The example below uses Embedded Replicas and syncs every minute from Turso. |
| 66 | + |
| 67 | +```ts |
| 68 | +import { createClient } from "@libsql/client"; |
| 69 | + |
| 70 | +export const turso = createClient({ |
| 71 | + url: "file:local.db", |
| 72 | + syncUrl: process.env.TURSO_DATABASE_URL, |
| 73 | + authToken: process.env.TURSO_AUTH_TOKEN, |
| 74 | + syncInterval: 60000, |
| 75 | +}); |
| 76 | + |
| 77 | +await client.batch( |
| 78 | + [ |
| 79 | + "CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)", |
| 80 | + { |
| 81 | + sql: "INSERT INTO users VALUES (?)", |
| 82 | + args: ["Iku"], |
| 83 | + }, |
| 84 | + ], |
| 85 | + "write", |
| 86 | +); |
| 87 | + |
| 88 | +await turso.execute({ |
| 89 | + sql: "SELECT * FROM users WHERE id = ?", |
| 90 | + args: [1], |
| 91 | +}); |
| 92 | +``` |
| 93 | + |
| 94 | +## Examples |
| 95 | + |
| 96 | +| Example | Description | |
| 97 | +| ------------------------------------- | --------------------------------------------------------------------------------------- | |
| 98 | +| [local](examples/local) | Uses libsql with a local SQLite file. Creates database, inserts data, and queries. | |
| 99 | +| [remote](examples/remote) | Connects to a remote database. Requires environment variables for URL and auth token. | |
| 100 | +| [sync](examples/sync) | Demonstrates synchronization between local and remote databases. | |
| 101 | +| [batch](examples/batch) | Executes multiple SQL statements in a single batch operation. | |
| 102 | +| [transactions](examples/transactions) | Shows transaction usage: starting, performing operations, and committing/rolling back. | |
| 103 | +| [memory](examples/memory) | Uses an in-memory SQLite database for temporary storage or fast access. | |
| 104 | +| [vector](examples/vector) | Works with vector embeddings, storing and querying for similarity search. | |
| 105 | +| [encryption](examples/encryption) | Creates and uses an encrypted SQLite database, demonstrating setup and data operations. | |
33 | 106 |
|
34 | 107 | ## Documentation
|
35 | 108 |
|
36 |
| -1. [Turso Quickstart](https://docs.turso.tech/quickstart) — Learn how create and connect your first database. |
37 |
| -2. [SDK Quickstart](https://docs.turso.tech/sdk/ts/quickstart) — Learn how to install and execute queries using the libSQL client. |
38 |
| -3. [SDK Reference](https://docs.turso.tech/sdk/ts/reference) — Dive deeper with the libSQL SDK reference and examples. |
| 109 | +Visit our [official documentation](https://docs.turso.tech/sdk/kotlin). |
| 110 | + |
| 111 | +## Support |
| 112 | + |
| 113 | +Join us [on Discord ](https://tur.so/discord-ts) to get help using this SDK. Report security issues [via email ](mailto:[email protected]). |
39 | 114 |
|
40 |
| -### What is Turso? |
| 115 | +## Contributors |
41 | 116 |
|
42 |
| -[Turso](https://turso.tech) is a SQLite-compatible database built on [libSQL](https://docs.turso.tech/libsql), the Open Contribution fork of SQLite. It enables scaling to hundreds of thousands of databases per organization and supports replication to any location, including your own servers, for microsecond-latency access. |
| 117 | +See the [contributing guide](CONTRIBUTING.md) to learn how to get involved. |
43 | 118 |
|
44 |
| -Learn more about what you can do with Turso: |
| 119 | + |
45 | 120 |
|
46 |
| -- [Embedded Replicas](https://docs.turso.tech/features/embedded-replicas) |
47 |
| -- [Platform API](https://docs.turso.tech/features/platform-api) |
48 |
| -- [Data Edge](https://docs.turso.tech/features/data-edge) |
49 |
| -- [Branching](https://docs.turso.tech/features/branching) |
50 |
| -- [Point-in-Time Recovery](https://docs.turso.tech/features/point-in-time-recovery) |
51 |
| -- [Scale to Zero](https://docs.turso.tech/features/scale-to-zero) |
| 121 | +<a href="https://github.com/tursodatabase/libsql-client-ts/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22"> |
| 122 | + <picture> |
| 123 | + <img src="https://img.shields.io/github/issues-search/tursodatabase/libsql-client-ts?label=good%20first%20issue&query=label%3A%22good%20first%20issue%22%20&color=0F624B" alt="good first issue" /> |
| 124 | + </picture> |
| 125 | +</a> |
0 commit comments