nestjs-libsql-client
Version:
NestJS TURSO libsql integration
240 lines (184 loc) • 5.7 kB
Markdown
<p align="center" style="vertical-align:middle">
<a href="https://nestjs.com/" target="blank">
<picture>
<img src="https://nestjs.com/img/logo_text.svg" width="200" alt="Nest Logo" />
</picture>
</a>
<a href="https://turso.tech/" target="blank">
<picture>
<img src=".github/cover.png" alt="Turso">
</picture>
</a>
</p>

[](https://codecov.io/gh/Adrianmjim/nestjs-libsql-client)
[](https://npmjs.org/package/nestjs-libsql-client)
[](https://www.npmjs.com/package/nestjs-libsql-client)
## Description
The [Turso Lib SQL client](https://github.com/tursodatabase/libsql-client) module for [NestJS](https://github.com/nestjs/nest).
## Installation
Install the dependencies via `npm`, `pnpm` or `yarn`:
npm:
```bash
$ npm i -s /common /client nestjs-libsql-client
```
pnpm:
```bash
$ pnpm add /common /client nestjs-libsql-client
```
yarn:
```bash
$ yarn add /common /client nestjs-libsql-client
```
## Configuration
First, import the module into your NestJS application and configure it using the configuration url provided by Turso or desired local configuration
```typescript
import { Module } from '@nestjs/common';
import { LibSqlModule } from 'nestjs-libsql-client';
export class AppModule {}
```
Or, You can configure it asynchronously as follows:
```typescript
import { Module } from '@nestjs/common';
import { LibSqlModule } from 'nestjs-libsql-client';
export class AppModule {}
```
## Multiple connections
In certain situations, we will need to connect to different Turso databases, with this module this is possible:
```typescript
import { Module } from '@nestjs/common';
import { LibSqlModule } from 'nestjs-libsql-client';
export class AppModule {}
```
Or asynchronously:
```typescript
import { Module } from '@nestjs/common';
import { LibSqlModule } from 'nestjs-libsql-client';
export class AppModule {}
```
## Usage
First, inject the client into the module where you want to use it:
```typescript
import { Module } from '@nestjs/common';
import { LibSqlModule } from 'nestjs-libsql-client';
export class CatModule {}
```
Or, for a specific connection:
```typescript
import { Module } from '@nestjs/common';
import { LibSqlModule } from 'nestjs-libsql-client';
export class CatModule {}
```
Now you can use the Turso libsql client in any provider of your module, just use `InjectLibSqlClient` decorator:
```typescript
import { Client } from '@libsql/client';
import { InjectLibSqlClient } from 'nestjs-libsql-client';
export class CatService {
constructor( private readonly libSqlClient: Client) {}
public doSomething(): void {
}
}
```
Or, for a specific connection:
```typescript
import { Client } from '@libsql/client';
import { InjectLibSqlClient } from 'nestjs-libsql-client';
export class CatService {
constructor(
private readonly libSqlClient: Client,
private readonly libSqlClient2: Client,
) {}
public doSomething(): void {
}
}
```
It's also possible to use the `InjectLibSqlClient` decorator to inject the libsql client when you don't want to explicitly type it with the client:
```typescript
import { InjectLibSqlClient } from 'nestjs-libsql-client';
export class CatService {
constructor(
private readonly libSqlClient: unknown,
) {}
public doSomething(): void {
}
}
```
## 🤝 Contributing [](https://github.com/adrianmjim/nestjs-libsql-client/issues)
Contributions, issues and feature requests are welcome.
## Authors
👤 **Adrián Martínez Jiménez**
- Github: [ ](https://github.com/adrianmjim)
See also the list of contributors who [participated](https://github.com/adrianmjim/nestjs-libsql-client/contributors) in this project.
## Show Your Support
Please ⭐️ this repository if this project helped you!
## 📝 License
Copyright © 2024 [Adrián Martínez Jiménez](https://github.com/adrianmjim).
This project is licensed under the MIT License - see the [LICENSE file](LICENSE) for details.