1.0.46 • Published 3 years ago

bb-mysql-helper v1.0.46

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

README.md

bb-mysql-helper

A NodeJS library to simplify the database connector

bb-mysql-helper is a Custom NPM Module (CNM), created by BroadenBlue Developers. It is focused to reduce the development code for database connection logic while creating projects from scratch especially. It also provides generic methods for CRUD operations.

Available Methods

  • fetch
  • fetchAll
  • insert
  • update
  • delete

Don't you want an easy way to communicate with your MySQL Database?

Installation

$ npm install bb-mysql-helper

Introduction

Database credentials are to be provided in the .env file on your server which must includes the specified keys below:

BB_MYSQL_HOST=<hostname>
BB_MYSQL_USER=<username>
BB_MYSQL_PASSWORD=<password>
BB_MYSQL_DATABASE=<db_name>

Building where condition

While executing the methods you need need pass atleast one key it should be either 'or' or 'and'.

const conditions = [
	{
    	or: {
        	email: {
            	condition: '=',
            	value: 'user@domain.com'
        	},
        	mobile: {
            	condition: 'in',
            	value: ['8XXXXXXXXX','9XXXXXXXXX']
        	}
    	},
    	and: {
        	is_deleted: {
            	condition: '=',
            	value: '0'
        	},
    	}
	}
]

Usage

Fetch

Used to fetch the selected columns of specified entity based on condition. Columns should be specified as a key-value pair in an object. In this object, key should be exactly match the database column name where as value can be passed which will be used as alias. If value is not passed, key itself will be used as alias.

Here is an example on how to use it:

import dbQ from "bb-mysql-helper";

dbQ.fetch({tableName:'users', cols:{email:'emailId',mobile:''},whereCondition: [{or:{},and:{}}]}).then((data)=>{
	data.forEach((element: any) => {
    	console.log(element.emailId,'--',element.mobile);
	});
});

FetchAll

Used to fetch the all columns of specified entity based on condition. No need to pass cols parameter in this method and whereCondition is optional and can be null if you want to fetch all the records in the database.

Here is an example on how to use it:

import dbQ from "bb-mysql-helper";

dbQ.fetchAll({tableName:'users', whereCondition: [{or:{},and:{}}]}).then((data)=>{
	data.forEach((element: any) => {
    	console.log(element.emailId,'--',element.mobile);
	});
});
1.0.44

3 years ago

1.0.43

3 years ago

1.0.42

3 years ago

1.0.41

3 years ago

1.0.46

3 years ago

1.0.45

3 years ago

1.0.40

3 years ago

1.0.39

3 years ago

1.0.38

3 years ago

1.0.37

3 years ago

1.0.36

3 years ago

1.0.35

3 years ago

1.0.34

3 years ago

1.0.33

3 years ago

1.0.32

3 years ago

1.0.31

3 years ago

1.0.30

3 years ago

1.0.29

3 years ago

1.0.28

3 years ago

1.0.27

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago