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
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
37 additions
and
23 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() {
this
.
daos
.
forEach
(
function
(
dao
)
{
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
)
{
if
(
dao
.
rawAttributes
.
hasOwnProperty
(
attrName
))
{
if
(
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
=
deps
.
filter
(
function
(
dep
)
{
return
dao
.
tableName
!==
dep
return
tableName
!==
dep
})
sorter
.
add
(
dao
.
tableName
,
deps
)
sorter
.
add
(
tableName
,
deps
)
})
sorted
=
sorter
.
sort
()
...
...
lib/dao-factory.js
View file @
a9dbf12
...
...
@@ -326,11 +326,7 @@ module.exports = (function() {
}
DAOFactory
.
prototype
.
drop
=
function
(
options
)
{
// Only Postgres' QueryGenerator.dropTableQuery() will add schema manually
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
)
return
this
.
QueryInterface
.
dropTable
(
this
.
getTableName
(),
options
)
}
DAOFactory
.
prototype
.
dropSchema
=
function
(
schema
)
{
...
...
lib/dialects/abstract/query-generator.js
View file @
a9dbf12
...
...
@@ -356,7 +356,7 @@ module.exports = (function() {
if
(
this
.
_dialect
.
supports
.
schemas
)
{
if
(
param
.
schema
)
{
table
+=
this
.
quoteIdentifier
(
param
.
schema
)
+
param
.
delimiter
table
+=
this
.
quoteIdentifier
(
param
.
schema
)
+
'.'
}
table
+=
this
.
quoteIdentifier
(
param
.
tableName
)
...
...
@@ -371,7 +371,7 @@ module.exports = (function() {
return
table
}
return
this
.
quoteIdentifier
(
param
)
return
this
.
quoteIdentifier
s
(
param
)
},
/*
...
...
@@ -506,12 +506,19 @@ module.exports = (function() {
Split an identifier into .-separated tokens and quote each part
*/
quoteIdentifiers
:
function
(
identifiers
,
force
)
{
return
identifiers
.
split
(
'.'
).
map
(
function
(
t
)
{
if
(
t
.
tableName
)
{
return
this
.
quoteTable
(
t
)
}
if
(
identifiers
.
indexOf
(
'.'
)
!==
-
1
)
{
identifiers
=
identifiers
.
split
(
'.'
)
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
])
}
}
else
{
return
this
.
quoteIdentifier
(
identifiers
)
}
},
/*
...
...
@@ -984,7 +991,7 @@ module.exports = (function() {
,
_result
=
[]
,
_value
if
(
typeof
value
===
'object'
)
{
if
(
_
.
isObject
(
value
)
)
{
if
(
value
.
join
)
{
//using as sentinel for join column => value
result
=
[
key
,
value
.
join
].
join
(
"="
)
...
...
lib/dialects/postgres/query-generator.js
View file @
a9dbf12
...
...
@@ -54,9 +54,9 @@ module.exports = (function() {
}
var
values
=
{
table
:
this
.
quote
Identifiers
(
tableName
),
table
:
this
.
quote
Table
(
tableName
),
attributes
:
attrStr
.
join
(
", "
),
comments
:
Utils
.
_
.
template
(
comments
,
{
table
:
this
.
quote
Identifiers
(
tableName
)})
comments
:
Utils
.
_
.
template
(
comments
,
{
table
:
this
.
quote
Table
(
tableName
)})
}
if
(
!!
options
.
uniqueKeys
)
{
...
...
@@ -456,7 +456,7 @@ module.exports = (function() {
if
(
dataType
.
references
)
{
template
+=
" REFERENCES <%= referencesTable %> (<%= referencesKey %>)"
replacements
.
referencesTable
=
this
.
quote
Identifiers
(
dataType
.
references
)
replacements
.
referencesTable
=
this
.
quote
Table
(
dataType
.
references
)
if
(
dataType
.
referencesKey
)
{
replacements
.
referencesKey
=
this
.
quoteIdentifiers
(
dataType
.
referencesKey
)
...
...
lib/query-interface.js
View file @
a9dbf12
...
...
@@ -27,6 +27,9 @@ module.exports = (function() {
QueryInterface
.
prototype
.
dropAllSchemas
=
function
()
{
var
self
=
this
if
(
!
this
.
QueryGenerator
.
_dialect
.
supports
.
schemas
)
{
return
this
.
dropAllTables
()
}
else
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
self
.
showAllSchemas
().
success
(
function
(
schemaNames
)
{
var
chainer
=
new
Utils
.
QueryChainer
()
...
...
@@ -37,6 +40,7 @@ module.exports = (function() {
}).
proxy
(
emitter
,
{
events
:
[
'sql'
,
'error'
]})
}).
run
()
}
}
QueryInterface
.
prototype
.
showAllSchemas
=
function
(
options
)
{
var
self
=
this
...
...
lib/sequelize.js
View file @
a9dbf12
test/associations/has-many.test.js
View file @
a9dbf12
...
...
@@ -601,8 +601,6 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
john
.
getTasks
({
where
:
{
active
:
true
}}).
success
(
function
(
tasks
)
{
expect
(
tasks
).
to
.
have
.
length
(
1
)
done
()
}).
on
(
'sql'
,
function
(
sql
)
{
console
.
log
(
sql
)
})
})
})
...
...
@@ -629,7 +627,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
username
:
DataTypes
.
STRING
}).
schema
(
'acme'
,
'_'
)
,
AcmeProject
=
self
.
sequelize
.
define
(
'Project'
,
{
title
:
DataTypes
.
STRING
,
active
:
DataTypes
.
BOOLEAN
title
:
DataTypes
.
STRING
,
active
:
DataTypes
.
BOOLEAN
}).
schema
(
'acme'
,
'_'
)
,
AcmeProjectUsers
=
self
.
sequelize
.
define
(
'ProjectUsers'
,
{
status
:
DataTypes
.
STRING
,
...
...
@@ -639,7 +638,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
AcmeUser
.
hasMany
(
AcmeProject
,
{
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
self
.
sequelize
.
createSchema
(
'acme'
).
done
(
function
(
err
)
{
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