Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 204e4cfa
authored
Oct 11, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
treat sqlite
1 parent
41eaf467
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
24 deletions
lib/query-interface.js
lib/query-interface.js
View file @
204e4cf
...
@@ -223,34 +223,45 @@ module.exports = (function() {
...
@@ -223,34 +223,45 @@ module.exports = (function() {
QueryInterface
.
prototype
.
dropAllTables
=
function
()
{
QueryInterface
.
prototype
.
dropAllTables
=
function
()
{
var
self
=
this
var
self
=
this
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
if
(
this
.
sequelize
.
options
.
dialect
===
'sqlite'
)
{
var
chainer
=
new
Utils
.
QueryChainer
()
// sqlite needs some special treatment as it cannot drop a column
return
SQLiteQueryInterface
.
dropAllTables
.
call
(
this
)
self
.
showAllTables
().
success
(
function
(
tableNames
)
{
}
else
{
chainer
.
add
(
self
,
'disableForeignKeyConstraints'
,
[])
return
new
Utils
.
CustomEventEmitter
(
function
(
dropAllTablesEmitter
)
{
var
events
=
[]
tableNames
.
forEach
(
function
(
tableName
)
{
,
chainer
=
new
Utils
.
QueryChainer
()
chainer
.
add
(
self
,
'dropTable'
,
[
tableName
,
{
cascade
:
true
}])
,
onError
=
function
(
err
)
{
})
self
.
emit
(
'dropAllTables'
,
err
)
dropAllTablesEmitter
.
emit
(
'error'
,
err
)
}
chainer
.
add
(
self
,
'enableForeignKeyConstraints'
,
[])
self
.
showAllTables
().
success
(
function
(
tableNames
)
{
self
.
getForeignKeysForTables
(
tableNames
).
success
(
function
(
foreignKeys
)
{
chainer
// add the foreign key removal query to the chainer
.
runSerially
()
Object
.
keys
(
foreignKeys
).
forEach
(
function
(
tableName
)
{
.
success
(
function
()
{
foreignKeys
[
tableName
].
forEach
(
function
(
foreignKey
)
{
self
.
emit
(
'dropAllTables'
,
null
)
var
sql
=
self
.
QueryGenerator
.
dropForeignKeyQuery
(
tableName
,
foreignKey
)
emitter
.
emit
(
'success'
,
null
)
chainer
.
add
(
self
.
sequelize
,
'query'
,
[
sql
])
})
})
})
.
error
(
function
(
err
)
{
self
.
emit
(
'dropAllTables'
,
err
)
// add the table removal query to the chainer
emitter
.
emit
(
'error'
,
err
)
tableNames
.
forEach
(
function
(
tableName
)
{
chainer
.
add
(
self
,
'dropTable'
,
[
tableName
,
{
cascade
:
true
}
])
})
})
}).
error
(
function
(
err
)
{
chainer
self
.
emit
(
'dropAllTables'
,
err
)
.
runSerially
()
emitter
.
emit
(
'error'
,
err
)
.
success
(
function
()
{
})
self
.
emit
(
'dropAllTables'
,
null
)
}).
run
()
dropAllTablesEmitter
.
emit
(
'success'
,
null
)
})
.
error
(
onError
)
}).
error
(
onError
)
}).
error
(
onError
)
}).
run
()
}
}
}
QueryInterface
.
prototype
.
renameTable
=
function
(
before
,
after
)
{
QueryInterface
.
prototype
.
renameTable
=
function
(
before
,
after
)
{
...
@@ -263,6 +274,7 @@ module.exports = (function() {
...
@@ -263,6 +274,7 @@ module.exports = (function() {
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
var
showTablesSql
=
self
.
QueryGenerator
.
showTablesQuery
()
var
showTablesSql
=
self
.
QueryGenerator
.
showTablesQuery
()
self
.
sequelize
.
query
(
showTablesSql
,
null
,
{
raw
:
true
}).
success
(
function
(
tableNames
)
{
self
.
sequelize
.
query
(
showTablesSql
,
null
,
{
raw
:
true
}).
success
(
function
(
tableNames
)
{
self
.
emit
(
'showAllTables'
,
null
)
self
.
emit
(
'showAllTables'
,
null
)
emitter
.
emit
(
'success'
,
Utils
.
_
.
flatten
(
tableNames
))
emitter
.
emit
(
'success'
,
Utils
.
_
.
flatten
(
tableNames
))
...
@@ -397,6 +409,35 @@ module.exports = (function() {
...
@@ -397,6 +409,35 @@ module.exports = (function() {
return
queryAndEmit
.
call
(
this
,
sql
,
'showIndex'
)
return
queryAndEmit
.
call
(
this
,
sql
,
'showIndex'
)
}
}
QueryInterface
.
prototype
.
getForeignKeysForTables
=
function
(
tableNames
)
{
var
self
=
this
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
if
(
tableNames
.
length
===
0
)
{
emitter
.
emit
(
'success'
,
{})
}
else
{
var
chainer
=
new
Utils
.
QueryChainer
()
tableNames
.
forEach
(
function
(
tableName
)
{
var
sql
=
self
.
QueryGenerator
.
getForeignKeysQuery
(
tableName
,
self
.
sequelize
.
config
.
database
)
chainer
.
add
(
self
.
sequelize
,
'query'
,
[
sql
])
})
chainer
.
runSerially
().
proxy
(
emitter
,
{
skipEvents
:
[
'success'
]
}).
success
(
function
(
results
)
{
var
result
=
{}
tableNames
.
forEach
(
function
(
tableName
,
i
)
{
result
[
tableName
]
=
Utils
.
_
.
compact
(
results
[
i
]).
map
(
function
(
r
)
{
return
r
.
constraint_name
})
})
emitter
.
emit
(
'success'
,
result
)
})
}
}).
run
()
}
QueryInterface
.
prototype
.
removeIndex
=
function
(
tableName
,
indexNameOrAttributes
)
{
QueryInterface
.
prototype
.
removeIndex
=
function
(
tableName
,
indexNameOrAttributes
)
{
var
sql
=
this
.
QueryGenerator
.
removeIndexQuery
(
tableName
,
indexNameOrAttributes
)
var
sql
=
this
.
QueryGenerator
.
removeIndexQuery
(
tableName
,
indexNameOrAttributes
)
return
queryAndEmit
.
call
(
this
,
sql
,
"removeIndex"
)
return
queryAndEmit
.
call
(
this
,
sql
,
"removeIndex"
)
...
@@ -439,7 +480,7 @@ module.exports = (function() {
...
@@ -439,7 +480,7 @@ module.exports = (function() {
chainer
.
runSerially
()
chainer
.
runSerially
()
.
success
(
function
(
results
){
.
success
(
function
(
results
){
emitter
.
query
=
{
sql
:
sql
}
emitter
.
query
=
{
sql
:
sql
}
emitter
.
emit
(
'success'
,
results
[
1
])
emitter
.
emit
(
'success'
,
results
[
0
])
emitter
.
emit
(
'sql'
,
sql
)
emitter
.
emit
(
'sql'
,
sql
)
})
})
.
error
(
function
(
err
)
{
.
error
(
function
(
err
)
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment