forked from taozhi8833998/node-sql-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete.js
More file actions
24 lines (22 loc) · 853 Bytes
/
delete.js
File metadata and controls
24 lines (22 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { columnsToSQL } from './column'
import { exprToSQL, orderOrPartitionByToSQL } from './expr'
import { limitToSQL } from './limit'
import { tablesToSQL } from './tables'
import { commonOptionConnector, hasVal } from './util'
function deleteToSQL(stmt) {
const clauses = ['DELETE']
const { columns, from, table, where, orderby, limit } = stmt
const columnInfo = columnsToSQL(columns, from)
clauses.push(columnInfo)
if (Array.isArray(table)) {
if (!(table.length === 1 && table[0].addition === true)) clauses.push(tablesToSQL(table))
}
clauses.push(commonOptionConnector('FROM', tablesToSQL, from))
clauses.push(commonOptionConnector('WHERE', exprToSQL, where))
clauses.push(orderOrPartitionByToSQL(orderby, 'order by'))
clauses.push(limitToSQL(limit))
return clauses.filter(hasVal).join(' ')
}
export {
deleteToSQL,
}