Socket
Socket
Sign inDemoInstall

@tfadev/easy-sqlite

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tfadev/easy-sqlite

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


Version published
Weekly downloads
32
decreased by-34.69%
Maintainers
1
Weekly downloads
 
Created
Source

@tfadev/easy-sqlite

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

npm install @tfadev/easy-sqlite

Usage

Create a new database using the class SQLiteDatabase:

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 }.

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.

type UsersSchema = {
    name: 'users',
    keys: {
        username: string,
        age: number,
        alive?: boolean, // ← Nullable
        languages: string[]
    }
};

new SQLiteDatabase<[UsersSchema, ...]>(...);

License

GNU General Public License (View here)

Keywords

FAQs

Package last updated on 30 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc