# @tfadev/easy-sqlite

> SQlite3 database but simplified with easy methods, with TypeScript support!

Latest version **1.1.0** (published 2023-10-30) · GPL-3.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @tfadev/easy-sqlite
pnpm add @tfadev/easy-sqlite
yarn add @tfadev/easy-sqlite
bun add @tfadev/easy-sqlite
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2023-10-30 |
| First published | 2023-09-13 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 58.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | TFAGaming |
| Maintainers | tfagaming |
| Keywords | sqlite, sqlite3, simple, database, db, simple database, simple db, easy, easy db, sql |

## Links

- npm: https://www.npmjs.com/package/@tfadev/easy-sqlite
- Repository: https://github.com/TFAGamingDev/easy-sqlite
- Homepage: https://github.com/TFAGamingDev/easy-sqlite#readme
- Issues: https://github.com/TFAGamingDev/easy-sqlite/issues
- npm.io page: https://npm.io/package/@tfadev/easy-sqlite

## Dependencies (1)

- [sqlite3](https://npm.io/package/sqlite3.md) ^5.1.6

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 1.1.0 (latest) — 2023-10-30
- 1.0.1 — 2023-10-21
- 1.0.0 — 2023-09-26
- 0.1.1 — 2023-09-13
- 0.1.0 — 2023-09-13

## README

<h1 align="center"> @tfadev/easy-sqlite</h1>

<p align="center">
    <img src="https://img.shields.io/discord/918611797194465280?color=7289da&logo=discord&logoColor=white&label=Discord">
    <img src="https://img.shields.io/npm/v/@tfadev/easy-sqlite.svg?maxAge=3600&logo=npm">
    <img src="https://img.shields.io/npm/dt/@tfadev/easy-sqlite.svg?maxAge=3600&label=Downloads">
</p>

SQlite3 database but simplified with easy methods, with TypeScript support!

## Features
- Supports arrays (string arras only).
- Supports boolean values.
- Simple and easy to use.
- Poweful typings.

## Installation
```sh-session
npm install @tfadev/easy-sqlite
```

## Usage

Create a new database using the class `SQLiteDatabase`:

```ts
import { SQLiteDatabase } from '@tfadev/easy-sqlite';

const db = new SQLiteDatabase('path/to/your/file.db');
```

Here are the available methods to use with `SQLiteDatabase` class.

> **Note**
> Every key is required (**NOT NULL**), you can make one or some of them optional by adding `{ nullable: true }`.

```ts
import { TableType } from '@tfadev/easy-sqlite';

// Creates a new table:
await db.create({
    name: 'users',
    overwrite: true, // IF EXISTS
    keys: {
        id: [TableType.Integer, {
            primary: true, // PRIMARY KEY
            autoincrement: true // AUTOINCREMENT
        }],
        username: [TableType.String],
        age: [TableType.Integer],
        alive: [TableType.Boolean, {
                nullable: true
        }],
        languages: [TableType.Array]
    }
});

// Insert a new row in a table:
await db.insert('users', {
    username: 'John',
    age: 35,
    alive: true,
    languages: ['Python', 'Typescript', 'C++']
});

// Select from a table, in an array output:
await db.select('users');
await db.select('users', { username: 'John' });

// Select from a table, in single output:
await db.selectFirst('users');
await db.selectFirst('users', { username: 'John' });

// Ensure if it exists or not:
await db.ensure('users');
await db.ensure('users', { username: 'John' });

// Deletes a row from a table:
await db.delete('users', { username: 'John' });

// Deletes a table:
await db.drop('users');

// Close the database:
await db.close();
```

## Typings

The class has a type parameter with type of array, you can include many schemas as you want, just make sure the types are correct and equal to created tables.

```ts
type UsersSchema = {
    name: 'users',
    keys: {
        username: string,
        age: number,
        alive?: boolean, // ← Nullable
        languages: string[]
    }
};

new SQLiteDatabase<[UsersSchema, ...]>(...);
```

## License
**GNU General Public License** ([View here](./LICENSE))

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