kaizer-db

1.2.7 • Public • Published

Kaizer DB

A lightweight and minimal csv database package

logo
Buy Me A Coffee

Features

  • SQL like syntax
  • Works directly with CSV
  • Supports all CRUD functionalities like INSERT, DELETE etc

Drawbacks

  • No type checking
  • Only one query at a time
  • Doesn't support data with spaces

Getting started

If you are using this package from the GitHub repository

  yarn start
  npm start

If you are using this package from the npm repository

  require('kaizer-db')

That's it! No fancy configuration or boiler code. It's as easy as that!!!

Usage

  • Creating or using a database

      Use Database dbname;
    
      Create Database dbname;
    

    Both these commands create a new folder named dbname where the tables are stored as csv files.

  • Show list of tables

      Show Tables;
    

    Shows list of available csv files in the current directory which is used as the database.

    first

  • Creating a table

     Create Table Warriors (Name,Attack,Defense,PowerLevel);
    

    Creates a file named Warriors.csv in the current folder dbname with the given headers.

  • Inserting data in a table

      Insert into Warriors (Name,Attack,Defense,PowerLevel) values (Goku,5000,7000,9001), (Vegeta,5000,7000,9000);
    

    Appends 2 records to the file named Warriors.csv

  • Getting records from a table

      Select * from Warriors;
    

    select1

      Select Name, PowerLevel from Warriors;
    

    select2

  • Getting records from a table using WHERE clause

      Select Name from Warriors Where PowerLevel > 9000;
    

    select3

  • Getting records from a table using multiple WHERE clauses

      Select * from Warriors Where PowerLevel > 9000 and Name = Goku;
    

    where1

      Select * from Warriors Where PowerLevel > 9000 or Name = Vegeta;
    

    where2

  • Updating a record using WHERE clause

      Update Table Warriors set PowerLevel = 10000, Defense = 8000 Where Name = Goku;
    

    updateQuery

  • Deleting a record using WHERE clause

      Delete From Warriors Where PowerLevel < 10000;
    

    select5

    Order by clause

    The default ordering is ascending order (asc,Asc,ASC)
    The descending order can be used as (desc,Desc,DESC)

    Examples

    Select * from test_data order by Defense;
    

    ser1

    Select * from test_data where Attack > 200 order by Defense desc;
    

    ser2

    Select Name, PowerLevel, Defense from test_data where Attack > 200 Order by Defense;
    

    ser3

    Error handling

    > Select Name, PowerLevel from test_data where Attack > 200 Order by Defense;
    Error: Order by field needs to be included in fetch list
    

    The sorting column must be present in the list of columns that needs to be fetched.

How to contribute

  • Fork the repository in your GitHub account.
  • Make your changes.
  • Submit a pull request.
  • Code should well documented.

Readme

Keywords

Package Sidebar

Install

npm i kaizer-db

Weekly Downloads

1

Version

1.2.7

License

MIT

Unpacked Size

38.3 kB

Total Files

18

Last publish

Collaborators

  • darkmortal