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 a9dbf12f
authored
Mar 09, 2014
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sqlite tests almost works now. Postgres = :(
1 parent
bea2e11e
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
48 additions
and
34 deletions
lib/dao-factory-manager.js
lib/dao-factory.js
lib/dialects/abstract/query-generator.js
lib/dialects/postgres/query-generator.js
lib/query-interface.js
lib/sequelize.js
test/associations/has-many.test.js
lib/dao-factory-manager.js
View file @
a9dbf12
...
@@ -52,24 +52,32 @@ module.exports = (function() {
...
@@ -52,24 +52,32 @@ module.exports = (function() {
this
.
daos
.
forEach
(
function
(
dao
)
{
this
.
daos
.
forEach
(
function
(
dao
)
{
var
deps
=
[]
var
deps
=
[]
,
tableName
=
dao
.
getTableName
()
daos
[
dao
.
tableName
]
=
dao
if
(
_
.
isObject
(
tableName
))
{
tableName
=
tableName
.
schema
+
'.'
+
tableName
.
tableName
}
daos
[
tableName
]
=
dao
for
(
var
attrName
in
dao
.
rawAttributes
)
{
for
(
var
attrName
in
dao
.
rawAttributes
)
{
if
(
dao
.
rawAttributes
.
hasOwnProperty
(
attrName
))
{
if
(
dao
.
rawAttributes
.
hasOwnProperty
(
attrName
))
{
if
(
dao
.
rawAttributes
[
attrName
].
references
)
{
if
(
dao
.
rawAttributes
[
attrName
].
references
)
{
dep
=
dao
.
rawAttributes
[
attrName
].
references
dep
=
dao
.
rawAttributes
[
attrName
].
references
dep
=
dep
.
tableName
||
dep
if
(
_
.
isObject
(
dep
))
{
dep
=
dep
.
schema
+
'.'
+
dep
.
tableName
}
deps
.
push
(
dep
)
deps
.
push
(
dep
)
}
}
}
}
}
}
deps
=
deps
.
filter
(
function
(
dep
)
{
deps
=
deps
.
filter
(
function
(
dep
)
{
return
dao
.
tableName
!==
dep
return
tableName
!==
dep
})
})
sorter
.
add
(
dao
.
tableName
,
deps
)
sorter
.
add
(
tableName
,
deps
)
})
})
sorted
=
sorter
.
sort
()
sorted
=
sorter
.
sort
()
...
...
lib/dao-factory.js
View file @
a9dbf12
...
@@ -326,11 +326,7 @@ module.exports = (function() {
...
@@ -326,11 +326,7 @@ module.exports = (function() {
}
}
DAOFactory
.
prototype
.
drop
=
function
(
options
)
{
DAOFactory
.
prototype
.
drop
=
function
(
options
)
{
// Only Postgres' QueryGenerator.dropTableQuery() will add schema manually
return
this
.
QueryInterface
.
dropTable
(
this
.
getTableName
(),
options
)
var
isPostgres
=
this
.
options
.
dialect
===
"postgres"
||
(
!!
this
.
daoFactoryManager
&&
this
.
daoFactoryManager
.
sequelize
.
options
.
dialect
===
"postgres"
)
,
tableName
=
isPostgres
?
this
.
tableName
:
this
.
getTableName
()
return
this
.
QueryInterface
.
dropTable
(
tableName
,
options
)
}
}
DAOFactory
.
prototype
.
dropSchema
=
function
(
schema
)
{
DAOFactory
.
prototype
.
dropSchema
=
function
(
schema
)
{
...
...
lib/dialects/abstract/query-generator.js
View file @
a9dbf12
...
@@ -356,7 +356,7 @@ module.exports = (function() {
...
@@ -356,7 +356,7 @@ module.exports = (function() {
if
(
this
.
_dialect
.
supports
.
schemas
)
{
if
(
this
.
_dialect
.
supports
.
schemas
)
{
if
(
param
.
schema
)
{
if
(
param
.
schema
)
{
table
+=
this
.
quoteIdentifier
(
param
.
schema
)
+
param
.
delimiter
table
+=
this
.
quoteIdentifier
(
param
.
schema
)
+
'.'
}
}
table
+=
this
.
quoteIdentifier
(
param
.
tableName
)
table
+=
this
.
quoteIdentifier
(
param
.
tableName
)
...
@@ -371,7 +371,7 @@ module.exports = (function() {
...
@@ -371,7 +371,7 @@ module.exports = (function() {
return
table
return
table
}
}
return
this
.
quoteIdentifier
(
param
)
return
this
.
quoteIdentifier
s
(
param
)
},
},
/*
/*
...
@@ -506,12 +506,19 @@ module.exports = (function() {
...
@@ -506,12 +506,19 @@ module.exports = (function() {
Split an identifier into .-separated tokens and quote each part
Split an identifier into .-separated tokens and quote each part
*/
*/
quoteIdentifiers
:
function
(
identifiers
,
force
)
{
quoteIdentifiers
:
function
(
identifiers
,
force
)
{
return
identifiers
.
split
(
'.'
).
map
(
function
(
t
)
{
if
(
identifiers
.
indexOf
(
'.'
)
!==
-
1
)
{
if
(
t
.
tableName
)
{
identifiers
=
identifiers
.
split
(
'.'
)
return
this
.
quoteTable
(
t
)
if
(
this
.
_dialect
.
supports
.
schemas
)
{
// quote every part
return
identifiers
.
map
(
function
(
t
)
{
return
this
.
quoteIdentifier
(
t
,
force
)
}.
bind
(
this
)).
join
(
'.'
)
}
else
{
// only quote the last part seperately
return
this
.
quoteIdentifier
(
identifiers
.
slice
(
0
,
identifiers
.
length
-
1
).
join
(
'.'
))
+
'.'
+
this
.
quoteIdentifier
(
identifiers
[
identifiers
.
length
-
1
])
}
}
return
this
.
quoteIdentifier
(
t
,
force
)
}
else
{
}.
bind
(
this
)).
join
(
'.'
)
return
this
.
quoteIdentifier
(
identifiers
)
}
},
},
/*
/*
...
@@ -984,7 +991,7 @@ module.exports = (function() {
...
@@ -984,7 +991,7 @@ module.exports = (function() {
,
_result
=
[]
,
_result
=
[]
,
_value
,
_value
if
(
typeof
value
===
'object'
)
{
if
(
_
.
isObject
(
value
)
)
{
if
(
value
.
join
)
{
if
(
value
.
join
)
{
//using as sentinel for join column => value
//using as sentinel for join column => value
result
=
[
key
,
value
.
join
].
join
(
"="
)
result
=
[
key
,
value
.
join
].
join
(
"="
)
...
...
lib/dialects/postgres/query-generator.js
View file @
a9dbf12
...
@@ -54,9 +54,9 @@ module.exports = (function() {
...
@@ -54,9 +54,9 @@ module.exports = (function() {
}
}
var
values
=
{
var
values
=
{
table
:
this
.
quote
Identifiers
(
tableName
),
table
:
this
.
quote
Table
(
tableName
),
attributes
:
attrStr
.
join
(
", "
),
attributes
:
attrStr
.
join
(
", "
),
comments
:
Utils
.
_
.
template
(
comments
,
{
table
:
this
.
quote
Identifiers
(
tableName
)})
comments
:
Utils
.
_
.
template
(
comments
,
{
table
:
this
.
quote
Table
(
tableName
)})
}
}
if
(
!!
options
.
uniqueKeys
)
{
if
(
!!
options
.
uniqueKeys
)
{
...
@@ -456,7 +456,7 @@ module.exports = (function() {
...
@@ -456,7 +456,7 @@ module.exports = (function() {
if
(
dataType
.
references
)
{
if
(
dataType
.
references
)
{
template
+=
" REFERENCES <%= referencesTable %> (<%= referencesKey %>)"
template
+=
" REFERENCES <%= referencesTable %> (<%= referencesKey %>)"
replacements
.
referencesTable
=
this
.
quote
Identifiers
(
dataType
.
references
)
replacements
.
referencesTable
=
this
.
quote
Table
(
dataType
.
references
)
if
(
dataType
.
referencesKey
)
{
if
(
dataType
.
referencesKey
)
{
replacements
.
referencesKey
=
this
.
quoteIdentifiers
(
dataType
.
referencesKey
)
replacements
.
referencesKey
=
this
.
quoteIdentifiers
(
dataType
.
referencesKey
)
...
...
lib/query-interface.js
View file @
a9dbf12
...
@@ -27,15 +27,19 @@ module.exports = (function() {
...
@@ -27,15 +27,19 @@ module.exports = (function() {
QueryInterface
.
prototype
.
dropAllSchemas
=
function
()
{
QueryInterface
.
prototype
.
dropAllSchemas
=
function
()
{
var
self
=
this
var
self
=
this
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
if
(
!
this
.
QueryGenerator
.
_dialect
.
supports
.
schemas
)
{
self
.
showAllSchemas
().
success
(
function
(
schemaNames
)
{
return
this
.
dropAllTables
()
var
chainer
=
new
Utils
.
QueryChainer
()
}
else
{
schemaNames
.
forEach
(
function
(
schemaName
)
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
chainer
.
add
(
self
.
dropSchema
(
schemaName
))
self
.
showAllSchemas
().
success
(
function
(
schemaNames
)
{
})
var
chainer
=
new
Utils
.
QueryChainer
()
chainer
.
run
().
proxy
(
emitter
)
schemaNames
.
forEach
(
function
(
schemaName
)
{
}).
proxy
(
emitter
,
{
events
:
[
'sql'
,
'error'
]})
chainer
.
add
(
self
.
dropSchema
(
schemaName
))
}).
run
()
})
chainer
.
run
().
proxy
(
emitter
)
}).
proxy
(
emitter
,
{
events
:
[
'sql'
,
'error'
]})
}).
run
()
}
}
}
QueryInterface
.
prototype
.
showAllSchemas
=
function
(
options
)
{
QueryInterface
.
prototype
.
showAllSchemas
=
function
(
options
)
{
...
...
lib/sequelize.js
View file @
a9dbf12
...
@@ -404,7 +404,7 @@ module.exports = (function() {
...
@@ -404,7 +404,7 @@ module.exports = (function() {
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
var
chainer
=
new
Utils
.
QueryChainer
()
var
chainer
=
new
Utils
.
QueryChainer
()
self
.
daoFactoryManager
.
forEachDAO
(
function
(
dao
)
{
self
.
daoFactoryManager
.
forEachDAO
(
function
(
dao
)
{
if
(
dao
)
{
if
(
dao
)
{
chainer
.
add
(
dao
,
'drop'
,
[])
chainer
.
add
(
dao
,
'drop'
,
[])
}
}
...
...
test/associations/has-many.test.js
View file @
a9dbf12
...
@@ -601,8 +601,6 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -601,8 +601,6 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
john
.
getTasks
({
where
:
{
active
:
true
}}).
success
(
function
(
tasks
)
{
john
.
getTasks
({
where
:
{
active
:
true
}}).
success
(
function
(
tasks
)
{
expect
(
tasks
).
to
.
have
.
length
(
1
)
expect
(
tasks
).
to
.
have
.
length
(
1
)
done
()
done
()
}).
on
(
'sql'
,
function
(
sql
)
{
console
.
log
(
sql
)
})
})
})
})
})
})
...
@@ -629,7 +627,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -629,7 +627,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
username
:
DataTypes
.
STRING
username
:
DataTypes
.
STRING
}).
schema
(
'acme'
,
'_'
)
}).
schema
(
'acme'
,
'_'
)
,
AcmeProject
=
self
.
sequelize
.
define
(
'Project'
,
{
,
AcmeProject
=
self
.
sequelize
.
define
(
'Project'
,
{
title
:
DataTypes
.
STRING
,
active
:
DataTypes
.
BOOLEAN
title
:
DataTypes
.
STRING
,
active
:
DataTypes
.
BOOLEAN
}).
schema
(
'acme'
,
'_'
)
}).
schema
(
'acme'
,
'_'
)
,
AcmeProjectUsers
=
self
.
sequelize
.
define
(
'ProjectUsers'
,
{
,
AcmeProjectUsers
=
self
.
sequelize
.
define
(
'ProjectUsers'
,
{
status
:
DataTypes
.
STRING
,
status
:
DataTypes
.
STRING
,
...
@@ -639,7 +638,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -639,7 +638,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
AcmeUser
.
hasMany
(
AcmeProject
,
{
through
:
AcmeProjectUsers
})
AcmeUser
.
hasMany
(
AcmeProject
,
{
through
:
AcmeProjectUsers
})
AcmeProject
.
hasMany
(
AcmeUser
,
{
through
:
AcmeProjectUsers
})
AcmeProject
.
hasMany
(
AcmeUser
,
{
through
:
AcmeProjectUsers
})
self
.
sequelize
.
dropAllSchemas
().
on
(
'sql'
,
function
(
sql
)
{
console
.
log
(
sql
);
}).
done
(
function
(
err
)
self
.
sequelize
.
dropAllSchemas
().
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
err
).
not
.
to
.
be
.
ok
self
.
sequelize
.
createSchema
(
'acme'
).
done
(
function
(
err
)
{
self
.
sequelize
.
createSchema
(
'acme'
).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
err
).
not
.
to
.
be
.
ok
...
...
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