Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@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 and TypeScript support!

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
23
increased by9.52%
Maintainers
1
Weekly downloads
 
Created
Source

@tfadev/easy-sqlite

SQlite3 database but simplified with easy methods and TypeScript support!

Features

  • Supports string arrays only (other types aren't supported yet).
  • Supports boolean values.
  • Simple and easy to use.
  • Poweful typings.

Installation

npm install @tfadev/discord.js-docs axios

Usage

Create a new database using the class SQLiteDatabase:

import { SQLiteDatabase } from '@tfadev/easy-sqlite';

const db = new SQLiteDatabase('path/to/your/sql/file.db');

Here are the available methods to use.

Note Every key is required (NOT NULL), you can make one or some of them optional by adding { nullable: true }.

// Creates a new table:
await db.create({
    {
        name: 'users',
        overwrite: true, // IF EXISTS
        keys: {
            id: ['INTEGER', {
                primary: true, // PRIMARY KEY
                autoincrement: true // AUTOINCREMENT
            }],
            username: ['TEXT'],
            age: ['INTEGER'],
            alive: ['BOOLEAN', {
                nullable: true
            }],
            languages: ['ARRAY']
        }
    }
});

// Deletes a table:
await db.drop('users', ...);

// Insert a new row in a table:
await db.insert('users', {
    username: 'T.F.A',
    age: 17,
    alive: true,
    languages: ['Python', 'Typescript', 'C++']
});

// Select from a table:
await db.select('users'); // → [{ ... }]

await db.select('users', { username: 'T.F.A' }); // → [{ ... }]
await db.select('users', { age: 17 }); // → [{ ... }]
await db.select('users', { username: 'T.F.A', age: 19 }); // → []

// Ensure if a table exist or not:
await db.ensure('users'); // → true

await db.ensure('users', { username: 'T.F.A' }); // → true
await db.ensure('users', { age: 17 }); // → true
await db.ensure('users', { username: 'T.F.A', age: 19 }); // → false

// Deletes a row from a table:
await db.delete('users', { username: 'T.F.A' });

Typings

The class has a type parameter, it serves for the typings of each method, here is an example:

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

const db = new SQLiteDatabase<Schema>(...);

License

GNU General Public License (View here)

Keywords

FAQs

Package last updated on 13 Sep 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