Let’s learn SWORM ORM with NodeJS and MSSQL.
What is ORM ?
Object-relational mapping (ORM) is a programming technique in which a metadata descriptor is used to connect object code to a relational database. It means this is a programming technique for converting data between incompatible type systems using object-oriented programming languages. ( TechOpedia and Wikipedia )
What is SWORM ?
A very lightweight write only Node.js ORM, with support for Microsoft SQL Server (MSSQL), PostgreSQL, MySQL, Oracle DB, Sqlite 3, Browser Web SQL. ( SWORM npm )
Create NodeJS Application
Using “npm init”, you can create a nodeJS application.
After that install MSSQL
Then install the below npm packages/Dependencies
Create a server.js file in your root folder and import SWORM to server.js file
After that your server.js file look like this.
Create DB connection String – SWORM MSSQL DB Connection String
In my application I created a another file called “db.config.js” to implement SWORM MSSQL DB connection string. Here is the code. Copy the below code.
Replace with your username and the password. And also rename the server name and the database name. You can select your driver.
Make sure to false the encrypt. Because it will give you an error called “self signed certificates failed”.
Let’s get into Code – Controllers and Models
You can create models like this.
But you don’t need to create a model for this ORM. Because in the controller SWORM will called the database table directly. Let’s see that.
This is the create new Port function.
You can see SWORM insert data to the database without calling models.
I am going to create a controller for get All Ports from the database table.
to get one Port from the database.
This is the end of “SWORM ORM with NodeJS and MSSQL” article. Thank you for reading. If you are interesting on my article, make sure to follow my other articles as well. Make sure to leave a comment.
- Android Studio Articles – https://builditmasters.com/category/android-studio/
- Android Studio Firebase Tutorial – https://builditmasters.com/category/android-studio-firebase-tutorial/
- C Programming – https://builditmasters.com/category/programming/
- Flutter – https://builditmasters.com/category/flutter/
- GitHub Tutorials – https://builditmasters.com/category/github/
- Java Programming – https://builditmasters.com/category/java-programming/
- MERN / MEVN Stacks – https://builditmasters.com/category/mern_mevn_stacks/
- Tech News – https://builditmasters.com/category/tech-news/
- Theory Lessons – https://builditmasters.com/category/theory-lessons/
- Adobe Tutorials – https://builditmasters.com/category/adobe-tutorials/
- Best Website for Programming – https://builditmasters.com/category/best-website-for-programming/
- Different Programming Styles – https://builditmasters.com/category/different-programming-styles/
- Earn Money – https://builditmasters.com/category/earn-money/
- Social Word – https://builditmasters.com/category/social-world/