npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

node-sql-connection

v1.0.0

Published

students-management db server - communicates with the server

Downloads

4

Readme

node-sql-connection

A module that execute migration between sql and config file.
You can create an SQL database from a config file.

A valid config file

The config file is a json file (in the future releases it will support more types of files)
The config file has two sections:

  1. database
  2. tables

the database interface


export interface DBConfig {
    database: string,  // the db name
    tables: EntityConfig[]  // an array of tables
}

the table interface

export interface TableConfig {
    MTDTable: {
        name: string, // the object name
        plural?:string, //the name for a list of connected items to a single one
        sqlName: string,  // the name of the table in sql
        description?: string, // a small description
        defaultColumns?: string[], // the default column/s to show when the entity is connected
        orderColumns?:string[] // the default order of the columns when quering it from the db
    },
    columns: ColumnConfig[]  // an array of columns
}

the column interface

export interface ColumnConfig {
    name: string,  // the property name
    sqlName: string, //the column's name in the SQL
    type: {
        type: string, //the sql type of the column
        allownull: boolean, //allow null
        max?: number,  // when the type is an NVARCHAR, you can add the max chracters number in a string 
        default?: any // a default value fr the column when no data has been defined 
    },
    primaryKey?: boolean, // primary key - false by default
    unique?: boolean, // unique - false by default
    isIdentity?: {
        offset: number,  // the offset number for identity column
        interval: number // the interval decrement number for identity column
    },
    foreignKey?: {
        ref_table: string,  // the referenced entity name 
        ref_column: string, // the references property name 
    }
}

config example

{
    "database":"USA",
    "tables":[
        {
            "MTDTable":{
                "name":"city",
                "sqlName":"tbl_city",
                "defaultColumns":["name", "country"],
                "orderColumns":["country", "name"]
            },
            "columns":[
                {"name":"id",
                "sqlName":"Id",
                "primaryKey":"true",
                "type":{
                    "type":"INT",
                    "allownull":"false"
                },
                "isIdentity":{
                    "offset":1,
                    "interval":1
                }
                }, {
                    "name":"name",
                    "sqlName":"Name",
                    "type":{
                        "type":"NVARCHAR",
                        "allownull":false,
                        "max":"20"
                    },
                    "unique": true
                 }, {
                    "name":"country",
                    "sqlName":"Country",
                    "type":{
                        "type":"NVARCHAR",
                        "allownull":false,
                        "max":"20"
                    }
                }
            ]
        }
    ]
}

createDB

the createDB function gets a valid json file to build the datbase in the sql add to the environment variables of your app the following variables

SQL_SERVER // the server name
SQL_USERNAME // the server username
SQL_PASSWORD  // the server password
SQL_PORT // the port
DATABASE // the default database to get to the sql (usualy master)

getObjects

the function returns data from the database, mapped to objects
params: {entityName: string, skip?:number, count?:number, url:string}

  • entityName: the entityname
  • url: the config file url
  • skip: how many records to skip - optional 0 by default
  • count: how many records to return - optional 50 by default
const data = await getObjects({entityName: 'city', skip:10, count:140, url:'./config.json'})

the function returns 140 records from the db. the query will skip the first 10 records.

getObjectsByCondition

the funcition returns records from the database by condition. the condition is a key, value object, and expand is a boolean param to indicate if each returned object should contain its connected entities. the expand param is optional, and by default it is false. the url is the address of the config file.

params: {entityName: string, condition:{[key:string]:any}, skip?:number, count?:number, url:string, expand:boolean}

const data = await getObjectsByCondition({entityName: 'city', condition:{country: 'Florida'}, count:20, url:'./config.json', expand: true})

the function will return the first 20 cities in Florida

countData

the function returns how many records fulfill to a certain condition
params: {entityName: string, condition?:{[key:string]:any}, url: string}

const count = await countData({entityName:'city', url:'./config.json'})

the function returns how many cities are in the db

const count = await countData({entityName:'city', condition:{country:'Florida', url:'./config.json'}})

the function returns how many cities are in Florida

insertItem

the function will insert a new record to the db, and if needed, it will add connected entities to the database with a transaction
params: {entityName: string, object:{[key:string]:any}, url: string}

const obj = await insertItem({entityName: 'city', object:{name:'New York', country: 'New York'}, url:'./config.json'})

updateItem

the function updates an existing object in the database
params: {entityName: string, object:{[key:string]:any}, url:string}
the object is the updated data of an object

const obj = await updateItem({entityName:'city', object:{id:3, name:'New-York'}, url:'./config.json'})

the New York city will be updated to New-York

updateItems

the function updates items that fulfill to the given condition.
params: {entityName: string, object:{[key:string]:any}, condition:{[key:string]:any}, url:string}
the object is the updated data fro all the objects

const obj = await updateItems({entityName:'city', condition:{country: 'florida'} object:{country:'Florida'}, url:'./config.json'})

all the cities that their country was florida, will be updated to Florida.

usage

run command from your app to create the database

"scripts":{
    "postbuild": "run-func node-sql-connection createDB ./data/config"
}

use the function inside the app

import {insertItem} from 'node-sql-connection'

const create = async({name, country}) => {
    
    const response = await insertItem({name, country})
    return response

}