myscl-server
v0.1.6
Published
A Lightweight NoSQL DB server with caching capabilities.
Downloads
23
Readme
MySCL
What is MySCL?
(To be completely clear, MySCL IS NOT MySQL)
MySCL is a lightweight NoSQL database with caching capabilities. MySCL is also a open-source database that is a implementation/re-written Redis and MongoDB combined. Lastly MySCL is a development database not meant for production applications.
[!WARNING] MySCL is still in the works and is one of my first projects. MySCL is not a production database!
Version Support
Linux
This database is made for Linux and is made in Linux. All the steps in this documentation are made specifically and only for Linux.
Windows
Try running WSL2 on your machine and running your project on WSL2. (I tested it on WSL2, it does work as good as Linux)
Unix (MacOS)
I haven't tested on Unix, it may work or not. The directory will be different for configuration obviously. (Why are you using Unix for development)
Setup Process
Installing Server
Installing the MySCL Database Server is quite simple using the npm package 'myscl-server'. To install the myscl-server package and use it, run the following command listed below.
sudo npm i myscl-server -g
Running the Server
In order to run the MySCL DB Server, run the listed commands below in order to start the db server.
sudo myscl
sudo myscl kill
sudo myscl start
The server will by default run on port 8000 and on host 127.0.0.1.
Configuring the database
In order to create a user, you must run the command below. If you do not configure a user you cannot access the database through your own application. (BETA FEATURE, just know it will require sudo to make sure no one else other than the admin is creating a new account)
sudo myscl add user
Next, all users must go to the configuration json file located in a certain directory. (THIS MAY VARY DEPENDING ON OS, CHECK SUPPORT VERSIONS) The directory for the configuration is listed below this text.
/usr/local/lib/node_modules/myscl-server/db
If this directory doesn't exist, you have encountered a problem with npm, or possibly with the myscl-server package.
If it does exist, the config.json file will contain all the necessary options to change the server. This directory also contains all the application data that your program will use like the databases, and collections/documents.
[!CAUTION] Edit the cli.json file at your own risk. (Editting this file can corrupt the CLI and DB) However this file is not meant for users to edit!
After making any changes to the database, do remember to run the command:
sudo myscl restart
Example Program
Configure your own node.js project and use the following command to install the myscl client:
npm i myscl-client
[!NOTE] Do refer to the myscl-client documentation for more information about the client and how to use it.
Create a new javascript file and put the following inside the file:
const { MySCL } = require("myscl-client")
/*
This is the default MySCL information,
if you changed the configuration do edit
the following constant below and change
the port if changed in the config.
Do make sure to not store your password in
your actual application! Store it in a
.env file of sorts or another file type.
Just don't store it in the file directly. (WARNING)
*/
const db = new MySCL("localhost", "8000", "username", "password")
async function main() {
await db.createDB("website")
await db.createCollection("website", "shop")
await db.insertOne("website", "shop", { name: "a", price: "a" })
await db.insertMany("website", "shop", [
{ name: "b", price: "b" },
{ name: "c", price: "c" },
{ name: "d", price: "c" },
{ name: "e", price: "e" }
])
const item_a = await db.findOne("website", "shop", { name: "a" })
const item_d = await db.findOne("website", "shop", { name: "d" })
console.log(item_a)
console.log(item_d)
await db.deleteOne("website", "shop", { name: "a" })
await db.deleteMany("website", "shop", { price: "c" })
}
main()
CLI Documentation
Initial Startup
As soon as you run the command, you will be prompted with a startup terminal screen. The command will start the server using a daemon.
sudo myscl
List Database Server
With the following command, you can see the PID, name, and the CPU/Memory data using:
myscl list
Starting, Stopping, Restarting
Starting the daemon is used typically for either the server crashed, or for restarting the daemon. The following command is:
myscl start
Stopping the daemon is used for if downtime is necessary, or if needed to restart which brings us to a better command for restarting. (The stop command is listed below)
myscl stop
Restarting the daemon is used for if the daemon fails, or an error occurs in the database. The command is listed below.
myscl restart
Creating, Deleting, Listing users
Creating a user is as simple as running the listed command. The command requires sudo to ensure that no other user is authorized to create a user and potentially gain access to the database.
sudo myscl add user
Once you've filled the information out, go ahead and run the following command to make sure that your user exists.
sudo myscl list users
And if you want to delete a user, run the command the following command,
sudo myscl delete user
Credits/License
This project is built under the MIT license. (This project is open-source) This was a solo project, and will still be maintained for a while.