DEV Community

Cover image for Node.js - Data persistency and a custom parser
Luis Felipe Ciochetta
Luis Felipe Ciochetta

Posted on

Node.js - Data persistency and a custom parser

Hey folks!

This is my second entry on my "devlog" for my database project, today I've started working on the data persistency and in the parsing of more complex inputs (strings with more than one word).


New functionalities

  • Data persistency: now whenever I call the command "using" or "create" or "insert" the database is writing itself to disk with the .ldb extension (it is still a JSON, I just made this so it would not keep triggering the nodemon whenever I made a change to any table)

Example:

Alt Text

  • Parsing strings with multiple words: in yesterday's version it wasn't possible to pass parameters with multiple words, now I've made a custom parser that supports it

Example:

Alt Text


Code structuring changes

First of all, I've cleaned some of my code, the parser file was getting way too big, so I moved some things around, this is my new structure:

Alt Text

  • commandExecutor: holds references for each command
  • database: returns the memory instance of the current database, allows me to set it to a new value, and saves the database
  • parser: transforms the input string into an array of commands and parameters

and the commands folder holds a file for each possible command:

Alt Text


Conclusion

loving to work on this project, I didn't even mean to write about it again before Christmas, but I was so happy with this morning's results that I could not wait

and again, this is the repository for this project, if anyone wants to check it out:

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…

Top comments (0)