DEV Community

Cover image for Creating a database from scratch with Node.js
Luis Felipe Ciochetta
Luis Felipe Ciochetta

Posted on

Creating a database from scratch with Node.js

Hey folks!

This is my first attempt at creating my own database from scratch. I am doing this for learning purposes and so I can say I have a database named after me;

Currently, in the first day of development, my main resource to study is this post, but I will not be doing a SQL database, instead, I will follow his steps but try to create a document database, like MongoDB


On this first day, my data is only stored in memory, I haven't yet started to work on the data persistency (actually saving it to disk).


Today I have implemented three functions:

Create

creates a new table; The current syntax for this function is:

Create [table name] [args...]
Enter fullscreen mode Exit fullscreen mode

Example:

Alt Text

Insert

adds a document to a table; the current syntax for this function is:

Insert [table name] [args...]
Enter fullscreen mode Exit fullscreen mode

Example:

Alt Text

Select

either returns each document for a table or the structure for the entire database; the current syntax for this function is:

Select [table name (optional)]
Enter fullscreen mode Exit fullscreen mode

Examples:

Alt Text


So yeah, this is what I've managed to create today, I will keep on improving it tomorrow and probably post about it after Christmas.

If anyone wants to try it or just to take a peek at source code, this is the GitHub repository for it:

GitHub logo ciochetta / learndb

Database project I've created for learning purposes

LuisDB

My study on how to create a database

Hello, this is the repository for my database project, I am trying to learn how to create a database from scratch using Node.js

My objective is to understand a little better how databases work internally

Installation

You need to have Node.js and NPM to install and use this project

npm i learndb
Enter fullscreen mode Exit fullscreen mode

Usage

you can use this in two ways, either as an REPL or as a driver for the database

REPL

If you want to use this project as a REPL I would adivise to clone it instead of installing it, if you have it cloned, to access the REPL, all you need to do is type this on the terminal:

node index.js repl
Enter fullscreen mode Exit fullscreen mode

REPL Commands

using [database name]

Either loads a database from the directory you are currently in or creates a database with the specified name if none…

And to run it, you just need to have an updated version of Node.js and write the following command in its root directory:

node index.js
Enter fullscreen mode Exit fullscreen mode

Top comments (0)