Skip to main content
Version: 1.2.4

Installation

Notice

npm i presql is deprecated, Package name has been changed presql to @enjoys/presql

Getting Started with PreSQL: Simplify Your Database Interactions

Welcome to PreSQL, the npm package that revolutionizes how you interact with databases in your Node.js projects. In this guide, we'll walk you through the steps to get started with PreSQL and introduce you to its powerful inbuilt functions and methods.

Getting Started

What you'll need

  • Node.js version 16.14 or above:
  • When installing Node.js, you are recommended to check all checkboxes related to dependencies.

Step 1: Installation
To begin, make sure you have Node.js installed on your system. Open your terminal or command prompt and run the following command to install PreSQL from the npm registry: Run this Command

npm i @enjoys/presql

Step 2: Setting up PreSQL
Once PreSQL is installed, you can start using it in your Node.js project. Require the package in your code using the following line. Create a new file connection.{js|ts}. Paste This Code.

connection.js
const { PreSqlClient } = require("@enjoys/presql");
const presql = new PreSqlClient({
pre_user: "root", //db username
pre_password: "", // dbpassword
pre_host: "localhost", //db host
pre_database: "db_name", //database name
pre_port: 3306,
});

module.exports = presql;

Extra Optional configuration

connection.js
const presql = new PreSqlClient({
pre_user: "root", //db username
pre_password: "", // dbpassword
pre_host: "localhost", //db host
pre_database: "db_name", //database name
pre_port: 3306, //optional field
/**
* Stringify objects instead of converting to values. (Default: 'false')
*/
pre_stringifyObjects: false,
/**
* Return each row as an array, not as an object.
* This is useful when you have duplicate column names.
* This can also be set in the `QueryOption` object to be applied per-query.
*/
rowsAsArray: false,
pre_timezone: "local", // optional field ,default time zone is local
showConnErrors: true, //optional field ,show connection log ,default false
resultLogs: true, //optional field ,show results in console,default false
tableJoiner: "_", // optional field, change only table joiner are different from _
multipleStatements:false, //optional field, make to true when use multiple statements at same time default true
});

if resultLogs is set to true

Output

ResultSetHeader {
fieldCount: 0,
affectedRows: 1,
insertId: 0,
info: '',
serverStatus: 2,
warningStatus: 0
}

if showConnErrors is set to true

 Database Connected Successfully