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 fa509566
authored
Sep 18, 2014
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made the set tests mysql specific, and more promisy
1 parent
66e40c39
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
63 deletions
lib/sequelize.js
test/sequelize.test.js
lib/sequelize.js
View file @
fa50956
...
@@ -563,24 +563,23 @@ module.exports = (function() {
...
@@ -563,24 +563,23 @@ module.exports = (function() {
};
};
/**
/**
* Execute a query which would set an environment or user variable.
* Execute a query which would set an environment or user variable. The variables are set per connection, so this function needs a transaction.
* If you want to set variables for a specific query, you should create a transaction and pass it on options.
*
*
* @method set
* @method set
* @param {Object} variables Object with multiple variables.
* @param {Object} variables Object with multiple variables.
* @param {Object} options={} Query options.
* @param {Object} options Query options.
* @param {Transaction} options.transaction=null The transaction that the query should be executed under
* @param {Transaction} options.transaction The transaction that the query should be executed under
* @return {Promise}
*
*
* @return {Promise}
*/
*/
Sequelize
.
prototype
.
set
=
function
(
variables
,
options
)
{
Sequelize
.
prototype
.
set
=
function
(
variables
,
options
)
{
var
query
;
var
query
;
// Prepare options
// Prepare options
options
=
Utils
.
_
.
extend
(
{},
this
.
options
.
set
,
typeof
options
===
'object'
&&
options
||
{}
);
options
=
Utils
.
_
.
extend
(
{},
this
.
options
.
set
,
typeof
options
===
'object'
&&
options
||
{}
);
if
(
!
options
.
transaction
||
!
(
options
.
transaction
instanceof
Transaction
)
)
{
if
(
!
options
.
transaction
||
!
(
options
.
transaction
instanceof
Transaction
)
)
{
return
Promise
.
rejected
(
new
TypeError
(
"options.transaction is required"
)
);
throw
new
TypeError
(
"options.transaction is required"
);
}
}
// Override some options, since this isn't a SELECT
// Override some options, since this isn't a SELECT
...
@@ -595,7 +594,7 @@ module.exports = (function() {
...
@@ -595,7 +594,7 @@ module.exports = (function() {
return
'@'
+
k
+
' := '
+
(
typeof
v
===
'string'
?
'"'
+
v
+
'"'
:
v
);
return
'@'
+
k
+
' := '
+
(
typeof
v
===
'string'
?
'"'
+
v
+
'"'
:
v
);
}).
join
(
', '
);
}).
join
(
', '
);
return
this
.
query
(
query
,
null
,
options
);
return
this
.
query
(
query
,
null
,
options
);
};
};
/**
/**
...
...
test/sequelize.test.js
View file @
fa50956
...
@@ -449,64 +449,45 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
...
@@ -449,64 +449,45 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
}
}
})
})
describe
(
'set'
,
function
()
{
if
(
Support
.
dialectIsMySQL
())
{
describe
(
'set'
,
function
()
{
it
(
"should return an promised error if transaction isn't defined"
,
function
(
done
)
{
it
(
"should return an promised error if transaction isn't defined"
,
function
()
{
var
S
=
this
.
sequelize
;
expect
(
function
()
{
this
.
sequelize
.
set
({
foo
:
'bar'
})
S
.
set
({
foo
:
'bar'
})
}.
bind
(
this
)).
to
.
throw
(
TypeError
,
"options.transaction is required"
)
.
done
(
function
(
err
)
{
expect
(
err
).
to
.
be
.
an
.
instanceof
(
TypeError
)
done
();
});
})
it
(
"one value"
,
function
(
done
)
{
var
S
=
this
.
sequelize
;
S
.
transaction
().
then
(
function
(
t
)
{
S
.
set
({
foo
:
'bar'
},
{
transaction
:
t
})
.
then
(
function
()
{
return
S
.
query
(
'SELECT @foo as `foo`'
,
null
,
{
raw
:
true
,
plain
:
true
,
transaction
:
t
})
})
.
then
(
function
(
data
)
{
expect
(
data
).
to
.
be
.
ok
expect
(
data
.
foo
).
to
.
be
.
equal
(
'bar'
)
})
.
then
(
function
()
{
return
t
.
commit
()
})
.
then
(
done
)
})
})
})
it
(
"multiple values"
,
function
(
done
)
{
it
(
"one value"
,
function
()
{
var
S
=
this
.
sequelize
;
return
this
.
sequelize
.
transaction
().
bind
(
this
).
then
(
function
(
t
)
{
this
.
t
=
t
;
return
this
.
sequelize
.
set
({
foo
:
'bar'
},
{
transaction
:
t
});
}).
then
(
function
()
{
return
this
.
sequelize
.
query
(
'SELECT @foo as `foo`'
,
null
,
{
raw
:
true
,
plain
:
true
,
transaction
:
this
.
t
});
}).
then
(
function
(
data
)
{
expect
(
data
).
to
.
be
.
ok
expect
(
data
.
foo
).
to
.
be
.
equal
(
'bar'
)
return
this
.
t
.
commit
();
});
});
S
.
transaction
().
then
(
function
(
t
)
{
it
(
"multiple values"
,
function
()
{
S
return
this
.
sequelize
.
transaction
().
bind
(
this
).
then
(
function
(
t
)
{
.
set
({
this
.
t
=
t
;
return
this
.
sequelize
.
set
({
foo
:
'bar'
,
foo
:
'bar'
,
foos
:
'bars'
,
foos
:
'bars'
,
},
{
transaction
:
t
})
},
{
transaction
:
t
});
.
then
(
function
()
{
}).
then
(
function
()
{
return
S
.
query
(
'SELECT @foo as `foo`, @foos as `foos`'
,
null
,
{
raw
:
true
,
plain
:
true
,
transaction
:
t
})
return
this
.
sequelize
.
query
(
'SELECT @foo as `foo`, @foos as `foos`'
,
null
,
{
raw
:
true
,
plain
:
true
,
transaction
:
this
.
t
});
})
}).
then
(
function
(
data
)
{
.
then
(
function
(
data
)
{
expect
(
data
).
to
.
be
.
ok
;
expect
(
data
).
to
.
be
.
ok
expect
(
data
.
foo
).
to
.
be
.
equal
(
'bar'
);
expect
(
data
.
foo
).
to
.
be
.
equal
(
'bar'
)
expect
(
data
.
foos
).
to
.
be
.
equal
(
'bars'
);
expect
(
data
.
foos
).
to
.
be
.
equal
(
'bars'
)
return
this
.
t
.
commit
();
})
});
.
then
(
function
()
{
});
return
t
.
commit
()
});
})
}
.
then
(
done
)
})
})
})
describe
(
'define'
,
function
()
{
describe
(
'define'
,
function
()
{
it
(
"adds a new dao to the dao manager"
,
function
(
done
)
{
it
(
"adds a new dao to the dao manager"
,
function
(
done
)
{
...
...
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