forked from taozhi8833998/node-sql-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.js
More file actions
55 lines (48 loc) · 1.25 KB
/
command.js
File metadata and controls
55 lines (48 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { identifierToSql, hasVal } from './util'
import { exprToSQL } from './expr'
import { tablesToSQL, tableToSQL } from './tables'
function dropToSQL(stmt) {
const clauses = ['DROP TABLE', tablesToSQL(stmt.table)]
return clauses.join(' ')
}
function truncateToSQL(stmt) {
const clauses = ['TRUNCATE', stmt.keyword, tablesToSQL(stmt.table)]
return clauses.filter(hasVal).join(' ')
}
function renameToSQL(stmt) {
const { type, table } = stmt
const clauses = []
const prefix = `${type && type.toUpperCase()} TABLE`
if (table) {
for (const tables of table) {
const renameInfo = tables.map(tableToSQL)
clauses.push(renameInfo.join(' TO '))
}
}
return `${prefix} ${clauses.join(', ')}`
}
function useToSQL(stmt) {
const { type, db } = stmt
const action = type && type.toUpperCase()
const database = identifierToSql(db)
return `${action} ${database}`
}
function callToSQL(stmt) {
const type = 'CALL'
const storeProcessCall = exprToSQL(stmt.expr)
return `${type} ${storeProcessCall}`
}
function setVarToSQL(stmt) {
const { expr } = stmt
const action = 'SET'
const val = exprToSQL(expr)
return `${action} ${val}`
}
export {
dropToSQL,
truncateToSQL,
renameToSQL,
useToSQL,
callToSQL,
setVarToSQL,
}