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 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-sql-mapper

v2.0.4

Published

Mapper for mysql node

Downloads

34

Readme

sql-mapper

How to install

npm i node-sql-mapper

Allowed Mapping Types

  • number : Float , Int ,... etc
  • string : Text , Varchar ,.... etc
  • datetime : Datetime
  • point : Point(X,Y)
  • polygon : Polygon [ {x , y} , {x, y} .... ]

How to run tests

npm install
npm test

Example for insertion

const fns = require('node-sql-mapper')
let mapping = {
  user_id: 'number',
  create_time: 'datetime',
  name: 'string',
  password: 'string',
  phone: 'number',
  location: 'point',
  borders: 'polygon'
}
let tableName = 'test_table'
let data = {
  location: {
    y: 12.22,
    x: 12.33
  },
  user_id: 123,
  create_time: new Date(),
  name: 'Harry Potter'
}
const sql = fns.insert({ data, mapping, tableName })
// sql will be "INSERT INTO test_table SET location = POINT(12.33,12.22)  `user_id` = 123, `create_time` = 2019-09-20 23:25:59.957, `name` = 'Harry Potter'"

Example for update

const fns = require('node-sql-mapper')
let mapping = {
  user_id: 'number',
  create_time: 'datetime',
  name: 'string',
  password: 'string',
  phone: 'number',
  location: 'point',
  borders: 'polygon'
}
let tableName = 'test_table'
let data = {
  name: 'Harry Potter'
}
let where = {
  user_id: 123
}
const sql = fns.update({ where, data, mapping, tableName })
// sql will be "UPDATE test_table SET `name` = 'Harry Potter' WHERE `user_id` = 123"

Example for advanced update

const fns = require('node-sql-mapper')
let mapping = {
  user_id: 'number',
  create_time: 'datetime',
  name: 'string',
  password: 'string',
  phone: 'number',
  location: 'point',
  borders: 'polygon'
}
let tableName = 'test_table'
let data = {
  name: 'Harry Potter'
}
let where = {
  and: {
    user_id: {
      '>': 123,
      '<': 1000
    },
    phone: 123456,
    create_time: {
      'not in': [new Date()]
    }
  }
}
const sql = fns.advancedUpdate({ where, data, mapping, tableName })
// sql will be "UPDATE test_table SET `name` = 'Harry Potter' WHERE `user_id` > 123 AND `user_id` < 1000 AND `phone` = 123456 AND `create_time` NOT IN('2019-10-02 00:13:21.897')"

Example for delete

const fns = require('node-sql-mapper')
let mapping = {
  user_id: 'number',
  create_time: 'datetime',
  name: 'string',
  password: 'string',
  phone: 'number',
  location: 'point',
  borders: 'polygon'
}
let tableName = 'test_table'
let where = {
  user_id: 123
}
const sql = fns.delete({ where, mapping, tableName })
// sql will be "DELETE FROM test_table WHERE `user_id` = 123"

Example for advanced delete

const fns = require('node-sql-mapper')
let mapping = {
  user_id: 'number',
  create_time: 'datetime',
  name: 'string',
  password: 'string',
  phone: 'number',
  location: 'point',
  borders: 'polygon'
}
let tableName = 'test_table'

let where = {
  and: {
    user_id: {
      '>': 123,
      '<': 1000
    },
    phone: 123456,
    create_time: {
      'not in': [new Date()]
    }
  }
}
const sql = fns.advancedDelete({ where, mapping, tableName })
// sql will be "DELETE FROM test_table WHERE `user_id` > 123 AND `user_id` < 1000 AND `phone` = 123456 AND `create_time` NOT IN('2019-10-02 00:14:22.254')"

Example for get

const fns = require('node-sql-mapper')
let mapping = {
  user_id: 'number',
  create_time: 'datetime',
  name: 'string',
  password: 'string',
  phone: 'number',
  location: 'point',
  borders: 'polygon'
}
let tableName = 'test_table'
let select = ['user_id', 'borders', 'ignored']
let where = {
  user_id: 123,
  phone: 123456
}
const sql = fns.get({ select, where, mapping, tableName })
// sql will be "SELECT 'user_id', 'borders' FROM test_table WHERE `user_id` = 123 AND `phone` = 123456"

Example for query

const fns = require('node-sql-mapper')
let mapping = {
  user_id: 'number',
  create_time: 'datetime',
  name: 'string',
  password: 'string',
  phone: 'number',
  location: 'point',
  borders: 'polygon'
}
let tableName = 'test_table'
let select = ['user_id', 'borders', 'ignored']
let where = {
  and: {
    user_id: {
      '>': 1,
      '<=': 5
    },
    phone: {
      in: [123, 321]
    }
  },
  or: {
    password: '123456'
  }
}
const sql = fns.query({ select, where, mapping, tableName })
// sql will be "SELECT `user_id`, `borders` FROM test_table WHERE `user_id` > 1 AND `user_id` <= 5 AND `phone` IN(123,321) OR `password` = '123456'"