不要怂,就是干,撸起袖子干!

Commit 72a940d8 by Andy Edwards Committed by GitHub

refactor: replace bluebird .get (#12071)

1 parent 33d7feea
...@@ -277,7 +277,7 @@ class QueryInterface { ...@@ -277,7 +277,7 @@ class QueryInterface {
} }
} }
return Promise.all(promises).get(0); return Promise.all(promises).then(obj => obj[0]);
}); });
} }
......
...@@ -47,7 +47,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => { ...@@ -47,7 +47,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => {
dateField: moment('2011 10 31', 'YYYY MM DD') dateField: moment('2011 10 31', 'YYYY MM DD')
}); });
}).then(() => { }).then(() => {
return User.findAll().get(0); return User.findAll().then(obj => obj[0]);
}).then(user => { }).then(user => {
expect(parse).to.have.been.called; expect(parse).to.have.been.called;
expect(stringify).to.have.been.called; expect(stringify).to.have.been.called;
...@@ -87,7 +87,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => { ...@@ -87,7 +87,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => {
field: value field: value
}); });
}).then(() => { }).then(() => {
return User.findAll().get(0); return User.findAll().then(obj => obj[0]);
}).then(() => { }).then(() => {
expect(parse).to.have.been.called; expect(parse).to.have.been.called;
if (options && options.useBindParam) { if (options && options.useBindParam) {
......
...@@ -71,7 +71,7 @@ if (dialect.match(/^postgres/)) { ...@@ -71,7 +71,7 @@ if (dialect.match(/^postgres/)) {
name: 'John Smythe' name: 'John Smythe'
}] }]
}); });
}).get('friends') }).then(obj => obj['friends'])
.then(friends => { .then(friends => {
expect(friends).to.have.length(1); expect(friends).to.have.length(1);
expect(friends[0].name).to.equal('John Smythe'); expect(friends[0].name).to.equal('John Smythe');
......
...@@ -52,7 +52,7 @@ if (dialect === 'sqlite') { ...@@ -52,7 +52,7 @@ if (dialect === 'sqlite') {
return this.User.create({ return this.User.create({
dateField: new Date(2010, 10, 10) dateField: new Date(2010, 10, 10)
}).then(() => { }).then(() => {
return this.User.findAll().get(0); return this.User.findAll().then(obj => obj[0]);
}).then(user => { }).then(user => {
expect(user.get('dateField')).to.be.an.instanceof(Date); expect(user.get('dateField')).to.be.an.instanceof(Date);
expect(user.get('dateField')).to.equalTime(new Date(2010, 10, 10)); expect(user.get('dateField')).to.equalTime(new Date(2010, 10, 10));
...@@ -67,7 +67,7 @@ if (dialect === 'sqlite') { ...@@ -67,7 +67,7 @@ if (dialect === 'sqlite') {
}, { include: [this.Project] }).then(() => { }, { include: [this.Project] }).then(() => {
return this.User.findAll({ return this.User.findAll({
include: [this.Project] include: [this.Project]
}).get(0); }).then(obj => obj[0]);
}).then(user => { }).then(user => {
expect(user.projects[0].get('dateField')).to.be.an.instanceof(Date); expect(user.projects[0].get('dateField')).to.be.an.instanceof(Date);
expect(user.projects[0].get('dateField')).to.equalTime(new Date(1990, 5, 5)); expect(user.projects[0].get('dateField')).to.equalTime(new Date(1990, 5, 5));
......
...@@ -123,7 +123,7 @@ describe(Support.getTestDialectTeaser('Paranoid'), () => { ...@@ -123,7 +123,7 @@ describe(Support.getTestDialectTeaser('Paranoid'), () => {
return X.findAll({ return X.findAll({
include: [Y] include: [Y]
}).get(0); }).then(obj => obj[0]);
}).then(x => { }).then(x => {
expect(x.ys).to.have.length(0); expect(x.ys).to.have.length(0);
}); });
......
...@@ -127,7 +127,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -127,7 +127,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('should apply default scope when including an associations', function() { it('should apply default scope when including an associations', function() {
return this.Company.findAll({ return this.Company.findAll({
include: [this.UserAssociation] include: [this.UserAssociation]
}).get(0).then(company => { }).then(obj => obj[0]).then(company => {
expect(company.users).to.have.length(2); expect(company.users).to.have.length(2);
}); });
}); });
...@@ -135,7 +135,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -135,7 +135,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('should apply default scope when including a model', function() { it('should apply default scope when including a model', function() {
return this.Company.findAll({ return this.Company.findAll({
include: [{ model: this.ScopeMe, as: 'users' }] include: [{ model: this.ScopeMe, as: 'users' }]
}).get(0).then(company => { }).then(obj => obj[0]).then(company => {
expect(company.users).to.have.length(2); expect(company.users).to.have.length(2);
}); });
}); });
...@@ -143,7 +143,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -143,7 +143,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('should be able to include a scoped model', function() { it('should be able to include a scoped model', function() {
return this.Company.findAll({ return this.Company.findAll({
include: [{ model: this.ScopeMe.scope('isTony'), as: 'users' }] include: [{ model: this.ScopeMe.scope('isTony'), as: 'users' }]
}).get(0).then(company => { }).then(obj => obj[0]).then(company => {
expect(company.users).to.have.length(1); expect(company.users).to.have.length(1);
expect(company.users[0].get('username')).to.equal('tony'); expect(company.users[0].get('username')).to.equal('tony');
}); });
...@@ -191,7 +191,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -191,7 +191,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
it('belongsToMany', function() { it('belongsToMany', function() {
return this.Project.findAll().get(0).then(p => { return this.Project.findAll().then(obj => obj[0]).then(p => {
return p.getCompanies({ scope: false }); return p.getCompanies({ scope: false });
}).then(companies => { }).then(companies => {
expect(companies).to.have.length(2); expect(companies).to.have.length(2);
...@@ -230,7 +230,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -230,7 +230,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
it('belongsToMany', function() { it('belongsToMany', function() {
return this.Project.findAll().get(0).then(p => { return this.Project.findAll().then(obj => obj[0]).then(p => {
return p.getCompanies(); return p.getCompanies();
}).then(companies => { }).then(companies => {
expect(companies).to.have.length(1); expect(companies).to.have.length(1);
...@@ -271,7 +271,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -271,7 +271,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
it('belongsToMany', function() { it('belongsToMany', function() {
return this.Project.findAll().get(0).then(p => { return this.Project.findAll().then(obj => obj[0]).then(p => {
return p.getCompanies({ scope: 'reversed' }); return p.getCompanies({ scope: 'reversed' });
}).then(companies => { }).then(companies => {
expect(companies).to.have.length(2); expect(companies).to.have.length(2);
......
...@@ -590,7 +590,7 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => { ...@@ -590,7 +590,7 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
const tickChar = dialect === 'postgres' || dialect === 'mssql' ? '"' : '`', const tickChar = dialect === 'postgres' || dialect === 'mssql' ? '"' : '`',
sql = `select 1 as ${Sequelize.Utils.addTicks('foo.bar.baz', tickChar)}`; sql = `select 1 as ${Sequelize.Utils.addTicks('foo.bar.baz', tickChar)}`;
return expect(this.sequelize.query(sql, { raw: true, nest: false }).get(0)).to.eventually.deep.equal([{ 'foo.bar.baz': 1 }]); return expect(this.sequelize.query(sql, { raw: true, nest: false }).then(obj => obj[0])).to.eventually.deep.equal([{ 'foo.bar.baz': 1 }]);
}); });
it('destructs dot separated attributes when doing a raw query using nest', function() { it('destructs dot separated attributes when doing a raw query using nest', function() {
...@@ -609,22 +609,22 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => { ...@@ -609,22 +609,22 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
}); });
it('replaces named parameters with the passed object', function() { it('replaces named parameters with the passed object', function() {
return expect(this.sequelize.query('select :one as foo, :two as bar', { raw: true, replacements: { one: 1, two: 2 } }).get(0)) return expect(this.sequelize.query('select :one as foo, :two as bar', { raw: true, replacements: { one: 1, two: 2 } }).then(obj => obj[0]))
.to.eventually.deep.equal([{ foo: 1, bar: 2 }]); .to.eventually.deep.equal([{ foo: 1, bar: 2 }]);
}); });
it('replaces named parameters with the passed object and ignore those which does not qualify', function() { it('replaces named parameters with the passed object and ignore those which does not qualify', function() {
return expect(this.sequelize.query('select :one as foo, :two as bar, \'00:00\' as baz', { raw: true, replacements: { one: 1, two: 2 } }).get(0)) return expect(this.sequelize.query('select :one as foo, :two as bar, \'00:00\' as baz', { raw: true, replacements: { one: 1, two: 2 } }).then(obj => obj[0]))
.to.eventually.deep.equal([{ foo: 1, bar: 2, baz: '00:00' }]); .to.eventually.deep.equal([{ foo: 1, bar: 2, baz: '00:00' }]);
}); });
it('replaces named parameters with the passed object using the same key twice', function() { it('replaces named parameters with the passed object using the same key twice', function() {
return expect(this.sequelize.query('select :one as foo, :two as bar, :one as baz', { raw: true, replacements: { one: 1, two: 2 } }).get(0)) return expect(this.sequelize.query('select :one as foo, :two as bar, :one as baz', { raw: true, replacements: { one: 1, two: 2 } }).then(obj => obj[0]))
.to.eventually.deep.equal([{ foo: 1, bar: 2, baz: 1 }]); .to.eventually.deep.equal([{ foo: 1, bar: 2, baz: 1 }]);
}); });
it('replaces named parameters with the passed object having a null property', function() { it('replaces named parameters with the passed object having a null property', function() {
return expect(this.sequelize.query('select :one as foo, :two as bar', { raw: true, replacements: { one: 1, two: null } }).get(0)) return expect(this.sequelize.query('select :one as foo, :two as bar', { raw: true, replacements: { one: 1, two: null } }).then(obj => obj[0]))
.to.eventually.deep.equal([{ foo: 1, bar: null }]); .to.eventually.deep.equal([{ foo: 1, bar: null }]);
}); });
...@@ -789,12 +789,12 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => { ...@@ -789,12 +789,12 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
if (Support.getTestDialect() === 'postgres') { if (Support.getTestDialect() === 'postgres') {
it('replaces named parameters with the passed object and ignores casts', function() { it('replaces named parameters with the passed object and ignores casts', function() {
return expect(this.sequelize.query('select :one as foo, :two as bar, \'1000\'::integer as baz', { raw: true, replacements: { one: 1, two: 2 } }).get(0)) return expect(this.sequelize.query('select :one as foo, :two as bar, \'1000\'::integer as baz', { raw: true, replacements: { one: 1, two: 2 } }).then(obj => obj[0]))
.to.eventually.deep.equal([{ foo: 1, bar: 2, baz: 1000 }]); .to.eventually.deep.equal([{ foo: 1, bar: 2, baz: 1000 }]);
}); });
it('supports WITH queries', function() { it('supports WITH queries', function() {
return expect(this.sequelize.query('WITH RECURSIVE t(n) AS ( VALUES (1) UNION ALL SELECT n+1 FROM t WHERE n < 100) SELECT sum(n) FROM t').get(0)) return expect(this.sequelize.query('WITH RECURSIVE t(n) AS ( VALUES (1) UNION ALL SELECT n+1 FROM t WHERE n < 100) SELECT sum(n) FROM t').then(obj => obj[0]))
.to.eventually.deep.equal([{ 'sum': '5050' }]); .to.eventually.deep.equal([{ 'sum': '5050' }]);
}); });
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!