Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
getWhereQuerys
✓ import { getWhereQuerys } from 'obj-2-sql'
✗ const getWhereQuerys = require('obj-2-sql')
ESM-only; module uses export syntax.
getSelectSql
✓ import { getSelectSql } from 'obj-2-sql'
default import
✓ import * as obj2sql from 'obj-2-sql'
✗ import obj2sql from 'obj-2-sql'
No default export; only named exports.
Demonstrates generating WHERE clause and full SELECT with JOIN, GROUP BY, HAVING, and pagination from object inputs.
import { getWhereQuerys, getSelectSql } from 'obj-2-sql';
// WHERE clause from array of conditions
const conditions = [
{ field: 'name', type: '=', value: 'bob' },
{ field: 'age', type: '>', value: 18 }
];
const whereQuery = getWhereQuerys(conditions);
console.log(whereQuery); // `name` = 'bob' AND `age` > 18
// Full SELECT with JOIN, GROUP BY, pagination
const selectSql = getSelectSql({
table: 'order_detail',
fields: [
{ field: 'product_id', table: 'order_detail' },
{ field: 'product_count', table: 'order_detail', aggType: 'SUM', alias: 'total_count' },
{ field: 'product_name', table: 'product' }
],
where: [{ field: { field: 'product_id', table: 'order_detail' }, type: '>', value: 1 }],
join: [
{
table: 'product',
on: [
{ table: 'order_detail', field: 'product_id' },
{ table: 'product', field: 'id' }
],
type: 'LEFT'
}
],
group: {
field: [
{ field: 'product_id', table: 'order_detail' },
{ field: 'product_name', table: 'product' }
],
having: [{ field: { table: 'order_detail', field: 'product_id' }, type: '>', value: 1 }]
},
page: { page: 3, pageSize: 20 }
});
console.log(selectSql);
// SELECT `order_detail`.`product_id`, SUM(`order_detail`.`product_count`) AS `total_count`, `product`.`product_name` FROM `order_detail` LEFT JOIN `product` ON `order_detail`.`product_id` = `product`.`id` WHERE `order_detail`.`product_id` > 1 GROUP BY `order_detail`.`product_id`, `product`.`product_name` HAVING `order_detail`.`product_id` > 1 LIMIT 40, 20
Errors
Common errors & fixes
getWhereQuerys(...) is not a function
Incorrect import (e.g., default import or require).
fixUse named import: import { getWhereQuerys } from 'obj-2-sql' Cannot read properties of undefined (reading 'field')
Passing an object instead of array to getWhereQuerys.
fixWrap single condition in array: [{field: 'name', type: '=', value: 'bob'}] 不支持的条件类型:<user_input>
Invalid operator string supplied to condition's 'type' field.
fixOnly use supported operators: '=', '>', '<', '>=', '<=', '!=', 'IN', 'NOT IN', 'LIKE', 'NOT LIKE'.
Audit
Dependencies
No dependency data recorded yet.