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 597b5e52
authored
Apr 16, 2015
by
Ruben Bridgewater
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return sequelize instance / dao after .sync and use promise.each instead of .reduce
1 parent
d732d0cf
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
23 deletions
lib/dialects/sqlite/query-interface.js
lib/query-interface.js
lib/sequelize.js
test/integration/include/findAll.test.js
test/integration/include/schema.test.js
test/integration/sequelize.test.js
lib/dialects/sqlite/query-interface.js
View file @
597b5e5
...
@@ -32,9 +32,9 @@ module.exports = {
...
@@ -32,9 +32,9 @@ module.exports = {
var
sql
=
self
.
QueryGenerator
.
removeColumnQuery
(
tableName
,
fields
)
var
sql
=
self
.
QueryGenerator
.
removeColumnQuery
(
tableName
,
fields
)
,
subQueries
=
sql
.
split
(
';'
).
filter
(
function
(
q
)
{
return
q
!==
''
;
});
,
subQueries
=
sql
.
split
(
';'
).
filter
(
function
(
q
)
{
return
q
!==
''
;
});
return
Utils
.
Promise
.
reduce
(
subQueries
,
function
(
total
,
subQuery
)
{
return
Utils
.
Promise
.
each
(
subQueries
,
function
(
subQuery
)
{
return
self
.
sequelize
.
query
(
subQuery
+
';'
,
null
,
{
raw
:
true
});
return
self
.
sequelize
.
query
(
subQuery
+
';'
,
null
,
{
raw
:
true
});
}
,
null
);
});
});
});
},
},
...
@@ -63,9 +63,9 @@ module.exports = {
...
@@ -63,9 +63,9 @@ module.exports = {
var
sql
=
self
.
QueryGenerator
.
removeColumnQuery
(
tableName
,
fields
)
var
sql
=
self
.
QueryGenerator
.
removeColumnQuery
(
tableName
,
fields
)
,
subQueries
=
sql
.
split
(
';'
).
filter
(
function
(
q
)
{
return
q
!==
''
;
});
,
subQueries
=
sql
.
split
(
';'
).
filter
(
function
(
q
)
{
return
q
!==
''
;
});
return
Utils
.
Promise
.
reduce
(
subQueries
,
function
(
total
,
subQuery
)
{
return
Utils
.
Promise
.
each
(
subQueries
,
function
(
subQuery
)
{
return
self
.
sequelize
.
query
(
subQuery
+
';'
,
null
,
{
raw
:
true
});
return
self
.
sequelize
.
query
(
subQuery
+
';'
,
null
,
{
raw
:
true
});
}
,
null
);
});
});
});
},
},
...
@@ -94,9 +94,9 @@ module.exports = {
...
@@ -94,9 +94,9 @@ module.exports = {
var
sql
=
self
.
QueryGenerator
.
renameColumnQuery
(
tableName
,
attrNameBefore
,
attrNameAfter
,
fields
)
var
sql
=
self
.
QueryGenerator
.
renameColumnQuery
(
tableName
,
attrNameBefore
,
attrNameAfter
,
fields
)
,
subQueries
=
sql
.
split
(
';'
).
filter
(
function
(
q
)
{
return
q
!==
''
;
});
,
subQueries
=
sql
.
split
(
';'
).
filter
(
function
(
q
)
{
return
q
!==
''
;
});
return
Utils
.
Promise
.
reduce
(
subQueries
,
function
(
total
,
subQuery
)
{
return
Utils
.
Promise
.
each
(
subQueries
,
function
(
subQuery
)
{
return
self
.
sequelize
.
query
(
subQuery
+
';'
,
null
,
{
raw
:
true
});
return
self
.
sequelize
.
query
(
subQuery
+
';'
,
null
,
{
raw
:
true
});
}
,
null
);
});
});
});
}
}
};
};
lib/query-interface.js
View file @
597b5e5
...
@@ -233,12 +233,12 @@ module.exports = (function() {
...
@@ -233,12 +233,12 @@ module.exports = (function() {
options
=
options
||
{};
options
=
options
||
{};
var
dropAllTables
=
function
(
tableNames
)
{
var
dropAllTables
=
function
(
tableNames
)
{
return
Utils
.
Promise
.
reduce
(
tableNames
,
function
(
total
,
tableName
)
{
return
Utils
.
Promise
.
each
(
tableNames
,
function
(
tableName
)
{
// if tableName is not in the Array of tables names then dont drop it
// if tableName is not in the Array of tables names then dont drop it
if
(
skip
.
indexOf
(
tableName
.
tableName
||
tableName
)
===
-
1
)
{
if
(
skip
.
indexOf
(
tableName
.
tableName
||
tableName
)
===
-
1
)
{
return
self
.
dropTable
(
tableName
,
{
cascade
:
true
});
return
self
.
dropTable
(
tableName
,
{
cascade
:
true
});
}
}
}
,
null
);
});
};
};
var
skip
=
options
.
skip
||
[];
var
skip
=
options
.
skip
||
[];
...
@@ -630,19 +630,19 @@ module.exports = (function() {
...
@@ -630,19 +630,19 @@ module.exports = (function() {
}
}
}
}
return
Promise
.
reduce
(
cascades
,
function
(
memo
,
cascade
)
{
return
Promise
.
each
(
cascades
,
function
(
cascade
)
{
return
dao
[
cascade
]({
return
dao
[
cascade
]({
transaction
:
options
.
transaction
transaction
:
options
.
transaction
}).
then
(
function
(
instances
)
{
}).
then
(
function
(
instances
)
{
if
(
!
Array
.
isArray
(
instances
))
instances
=
[
instances
];
if
(
!
Array
.
isArray
(
instances
))
instances
=
[
instances
];
return
Promise
.
reduce
(
instances
,
function
(
memo
,
instance
)
{
return
Promise
.
each
(
instances
,
function
(
instance
)
{
return
instance
.
destroy
({
return
instance
.
destroy
({
transaction
:
options
.
transaction
transaction
:
options
.
transaction
});
});
}
,
[]
);
});
});
});
}
,
[]
).
then
(
function
()
{
}).
then
(
function
()
{
return
self
.
sequelize
.
query
(
sql
,
dao
,
options
);
return
self
.
sequelize
.
query
(
sql
,
dao
,
options
);
});
});
};
};
...
...
lib/sequelize.js
View file @
597b5e5
...
@@ -892,9 +892,10 @@ module.exports = (function() {
...
@@ -892,9 +892,10 @@ module.exports = (function() {
}
}
});
});
return
Promise
.
reduce
(
daos
,
function
(
total
,
dao
)
{
return
Promise
.
each
(
daos
,
function
(
dao
)
{
return
dao
.
sync
(
options
);
return
dao
.
sync
(
options
);
},
null
);
// return the sequelize instance
}).
return
(
self
);
});
});
};
};
...
@@ -912,11 +913,11 @@ module.exports = (function() {
...
@@ -912,11 +913,11 @@ module.exports = (function() {
if
(
dao
)
{
if
(
dao
)
{
daos
.
push
(
dao
);
daos
.
push
(
dao
);
}
}
},
{
reverse
:
false
});
},
{
reverse
:
false
});
return
Promise
.
reduce
(
daos
,
function
(
total
,
dao
)
{
return
Promise
.
each
(
daos
,
function
(
dao
)
{
return
dao
.
drop
(
options
);
return
dao
.
drop
(
options
);
}
,
null
);
});
};
};
/**
/**
...
...
test/integration/include/findAll.test.js
View file @
597b5e5
...
@@ -128,7 +128,7 @@ describe(Support.getTestDialectTeaser('Include'), function() {
...
@@ -128,7 +128,7 @@ describe(Support.getTestDialectTeaser('Include'), function() {
,
tags
=
results
.
tags
,
tags
=
results
.
tags
,
companies
=
results
.
companies
;
,
companies
=
results
.
companies
;
return
Promise
.
resolve
([
0
,
1
,
2
,
3
,
4
]).
each
(
function
(
i
)
{
return
Promise
.
each
([
0
,
1
,
2
,
3
,
4
],
function
(
i
)
{
return
Promise
.
props
({
return
Promise
.
props
({
user
:
User
.
create
(),
user
:
User
.
create
(),
products
:
Product
.
bulkCreate
([
products
:
Product
.
bulkCreate
([
...
@@ -398,7 +398,7 @@ describe(Support.getTestDialectTeaser('Include'), function() {
...
@@ -398,7 +398,7 @@ describe(Support.getTestDialectTeaser('Include'), function() {
return
Tag
.
findAll
();
return
Tag
.
findAll
();
})
})
]).
spread
(
function
(
groups
,
ranks
,
tags
)
{
]).
spread
(
function
(
groups
,
ranks
,
tags
)
{
return
Promise
.
resolve
([
0
,
1
,
2
,
3
,
4
]).
each
(
function
(
i
)
{
return
Promise
.
each
([
0
,
1
,
2
,
3
,
4
],
function
(
i
)
{
return
Promise
.
all
([
return
Promise
.
all
([
User
.
create
(),
User
.
create
(),
Product
.
bulkCreate
([
Product
.
bulkCreate
([
...
@@ -1267,7 +1267,7 @@ describe(Support.getTestDialectTeaser('Include'), function() {
...
@@ -1267,7 +1267,7 @@ describe(Support.getTestDialectTeaser('Include'), function() {
return
Tag
.
findAll
();
return
Tag
.
findAll
();
})
})
]).
spread
(
function
(
groups
,
ranks
,
tags
)
{
]).
spread
(
function
(
groups
,
ranks
,
tags
)
{
return
Promise
.
resolve
([
0
,
1
,
2
,
3
,
4
]).
each
(
function
(
i
)
{
return
Promise
.
each
([
0
,
1
,
2
,
3
,
4
],
function
(
i
)
{
return
Promise
.
props
({
return
Promise
.
props
({
user
:
User
.
create
({
name
:
'FooBarzz'
}),
user
:
User
.
create
({
name
:
'FooBarzz'
}),
products
:
Product
.
bulkCreate
([
products
:
Product
.
bulkCreate
([
...
...
test/integration/include/schema.test.js
View file @
597b5e5
...
@@ -126,7 +126,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
...
@@ -126,7 +126,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
Tag
.
findAll
()
Tag
.
findAll
()
]);
]);
}).
spread
(
function
(
groups
,
companies
,
ranks
,
tags
)
{
}).
spread
(
function
(
groups
,
companies
,
ranks
,
tags
)
{
return
Promise
.
resolve
([
0
,
1
,
2
,
3
,
4
]).
each
(
function
(
i
)
{
return
Promise
.
each
([
0
,
1
,
2
,
3
,
4
],
function
(
i
)
{
return
Promise
.
all
([
return
Promise
.
all
([
AccUser
.
create
(),
AccUser
.
create
(),
Product
.
bulkCreate
([
Product
.
bulkCreate
([
...
@@ -268,7 +268,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
...
@@ -268,7 +268,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
return
Tag
.
findAll
();
return
Tag
.
findAll
();
})
})
]).
spread
(
function
(
groups
,
ranks
,
tags
)
{
]).
spread
(
function
(
groups
,
ranks
,
tags
)
{
return
Promise
.
resolve
([
0
,
1
,
2
,
3
,
4
]).
each
(
function
(
i
)
{
return
Promise
.
each
([
0
,
1
,
2
,
3
,
4
],
function
(
i
)
{
return
Promise
.
all
([
return
Promise
.
all
([
AccUser
.
create
(),
AccUser
.
create
(),
Product
.
bulkCreate
([
Product
.
bulkCreate
([
...
@@ -383,7 +383,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
...
@@ -383,7 +383,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
{},
{},
{},
{},
{},
{},
{},
{}
{},
{},
{},
{},
{},
{},
{},
{}
]).
then
(
function
()
{
]).
then
(
function
()
{
var
previousInstance
;
var
previousInstance
;
return
Promise
.
resolve
(
singles
).
each
(
function
(
model
)
{
return
Promise
.
each
(
singles
,
function
(
model
)
{
return
model
.
create
({}).
then
(
function
(
instance
)
{
return
model
.
create
({}).
then
(
function
(
instance
)
{
if
(
previousInstance
)
{
if
(
previousInstance
)
{
return
previousInstance
[
'set'
+
Sequelize
.
Utils
.
uppercaseFirst
(
model
.
name
)](
instance
).
then
(
function
()
{
return
previousInstance
[
'set'
+
Sequelize
.
Utils
.
uppercaseFirst
(
model
.
name
)](
instance
).
then
(
function
()
{
...
...
test/integration/sequelize.test.js
View file @
597b5e5
...
@@ -774,6 +774,28 @@ describe(Support.getTestDialectTeaser('Sequelize'), function() {
...
@@ -774,6 +774,28 @@ describe(Support.getTestDialectTeaser('Sequelize'), function() {
return
this
.
sequelize
.
sync
();
return
this
.
sequelize
.
sync
();
});
});
it
(
'return the sequelize instance after syncing'
,
function
()
{
var
self
=
this
;
return
this
.
sequelize
.
sync
().
then
(
function
(
sequelize
)
{
expect
(
sequelize
).
to
.
deep
.
equal
(
self
.
sequelize
);
});
});
it
(
'return the single dao after syncing'
,
function
()
{
var
block
=
this
.
sequelize
.
define
(
'block'
,
{
id
:
{
type
:
DataTypes
.
INTEGER
,
primaryKey
:
true
},
name
:
DataTypes
.
STRING
},
{
tableName
:
'block'
,
timestamps
:
false
,
paranoid
:
false
});
return
block
.
sync
().
then
(
function
(
result
)
{
expect
(
result
).
to
.
deep
.
equal
(
block
);
});
});
}
}
describe
(
"doesn't emit logging when explicitly saying not to"
,
function
()
{
describe
(
"doesn't emit logging when explicitly saying not to"
,
function
()
{
...
...
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