DEV Community

Ali Azmoodeh
Ali Azmoodeh

Posted on • Edited on

New Node.js ORM(Opensql)

It's 2023 and I want to introduce you to a new orm for node.js

Introduction

Opensql is a new project that was started on Jun 23, 2022. Its initial version was released on Jun 27 and it only supported mysql driver. Currently, version 2.0.6 of three databases (Mysql, Postgresql, Microsoft Sql Server) supports in this post, we will implement the crud operation in opensql, let's get started :)

Install and setup

To start the installation from the npm package manager, (
๐Ÿ“’Note: make sure to install npm on your system), then write the following command and wait for opensql to be installed.

npm i opensql

๐Ÿ“’Tip: Install the database driver you want to use in your project, For more information, refer to this link. In the link, there is a list of drivers along with the package name.

How to use

Connection

The way to connect to the desired database is very easy. The bottom part is the simple way to connect to the mysql database.

Image description

As you can see, the connection method is possible with only one text string. You can use its second parameter to apply option changes in the database.

CRUD

SELECT

To write a select query, you can use the find method and enter the name of your table as shown below :

Image description1

You can also filter your data using the where keyword :

Image description

INSERT

The insert operation is possible in two ways in opensql. The first method is to use the addOne method. This method adds only one row to the table:

Image description

The second method is the addMany method. Using this method, you can add several consecutive queries to your table.

Image description

UPDATE

The update method allows you to update your data :

Image description

DELETE

The remove method allows you to delete your data :

Image description

Full source code on GitHub

We have reached the end of the training, opensql has other methods, if you are interested in it, you can refer to this link

If you had a problem or encountered an error, or if you have an idea to improve this project, you can let us know on GitHub. If you also want to contribute to the project, refer to this link.

Top comments (0)