sql-mapper
How to install
npm i node-sql-mapper
Allowed Mapping Types
number
: Float , Int ,... etcstring
: Text , Varchar ,.... etcdatetime
: Datetimepoint
: Point(X,Y)polygon
: Polygon [ {x , y} , {x, y} .... ]
How to run tests
npm install
npm test
Example for insertion
const fns = 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: 1222 x: 1233 user_id: 123 create_time: name: 'Harry Potter'const sql = fns// 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 = 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: 123const sql = fns// sql will be "UPDATE test_table SET `name` = 'Harry Potter' WHERE `user_id` = 123"
Example for advanced update
const fns = 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': const sql = fns// 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 = 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: 123const sql = fns// sql will be "DELETE FROM test_table WHERE `user_id` = 123"
Example for advanced delete
const fns = 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': const sql = fns// 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 = 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: 123456const sql = fns// sql will be "SELECT 'user_id', 'borders' FROM test_table WHERE `user_id` = 123 AND `phone` = 123456"
Example for query
const fns = 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// 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'"