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 94ae7cef
authored
Nov 24, 2014
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move the formatResults func to mysql query
1 parent
b8583cd6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
59 deletions
lib/dialects/abstract/query.js
lib/dialects/mysql/query.js
lib/dialects/abstract/query.js
View file @
94ae7ce
...
...
@@ -47,65 +47,6 @@ module.exports = (function() {
};
/**
* High level function that handles the results of a query execution.
*
*
* Example:
* query.formatResults([
* {
* id: 1, // this is from the main table
* attr2: 'snafu', // this is from the main table
* Tasks.id: 1, // this is from the associated table
* Tasks.title: 'task' // this is from the associated table
* }
* ])
*
* @param {Array} data - The result of the query execution.
*/
AbstractQuery
.
prototype
.
formatResults
=
function
(
data
)
{
var
result
=
this
.
callee
;
if
(
this
.
isInsertQuery
(
data
))
{
this
.
handleInsertQuery
(
data
);
}
if
(
this
.
isSelectQuery
())
{
result
=
this
.
handleSelectQuery
(
data
);
}
else
if
(
this
.
isShowTableQuery
())
{
result
=
this
.
handleShowTableQuery
(
data
);
}
else
if
(
this
.
isShowOrDescribeQuery
())
{
result
=
data
;
if
(
this
.
sql
.
toLowerCase
().
indexOf
(
'describe'
)
===
0
)
{
result
=
{};
data
.
forEach
(
function
(
_result
)
{
result
[
_result
.
Field
]
=
{
type
:
_result
.
Type
.
toUpperCase
(),
allowNull
:
(
_result
.
Null
===
'YES'
),
defaultValue
:
_result
.
Default
};
});
}
else
if
(
this
.
isShowIndexesQuery
())
{
result
=
this
.
handleShowIndexesQuery
(
data
);
}
}
else
if
(
this
.
isCallQuery
())
{
result
=
data
[
0
];
}
else
if
(
this
.
isBulkUpdateQuery
()
||
this
.
isBulkDeleteQuery
())
{
result
=
data
.
affectedRows
;
}
else
if
(
this
.
isUpsertQuery
())
{
if
(
data
.
affectedRows
===
2
)
{
// In MySQL, affectedRows = 2 means that the ON DUPLICATE KEY clause was executed
result
=
0
;
}
else
{
result
=
data
.
affectedRows
;
}
}
return
result
;
};
/**
* Get the attributes of an insert query, which contains the just inserted id.
*
* @return {String} The field name.
...
...
lib/dialects/mysql/query.js
View file @
94ae7ce
...
...
@@ -46,6 +46,59 @@ module.exports = (function() {
return
promise
;
};
/**
* High level function that handles the results of a query execution.
*
*
* Example:
* query.formatResults([
* {
* id: 1, // this is from the main table
* attr2: 'snafu', // this is from the main table
* Tasks.id: 1, // this is from the associated table
* Tasks.title: 'task' // this is from the associated table
* }
* ])
*
* @param {Array} data - The result of the query execution.
*/
Query
.
prototype
.
formatResults
=
function
(
data
)
{
var
result
=
this
.
callee
;
if
(
this
.
isInsertQuery
(
data
))
{
this
.
handleInsertQuery
(
data
);
}
if
(
this
.
isSelectQuery
())
{
result
=
this
.
handleSelectQuery
(
data
);
}
else
if
(
this
.
isShowTableQuery
())
{
result
=
this
.
handleShowTableQuery
(
data
);
}
else
if
(
this
.
isShowOrDescribeQuery
())
{
result
=
data
;
if
(
this
.
sql
.
toLowerCase
().
indexOf
(
'describe'
)
===
0
)
{
result
=
{};
data
.
forEach
(
function
(
_result
)
{
result
[
_result
.
Field
]
=
{
type
:
_result
.
Type
.
toUpperCase
(),
allowNull
:
(
_result
.
Null
===
'YES'
),
defaultValue
:
_result
.
Default
};
});
}
else
if
(
this
.
isShowIndexesQuery
())
{
result
=
this
.
handleShowIndexesQuery
(
data
);
}
}
else
if
(
this
.
isCallQuery
())
{
result
=
data
[
0
];
}
else
if
(
this
.
isBulkUpdateQuery
()
||
this
.
isBulkDeleteQuery
()
||
this
.
isUpsertQuery
())
{
result
=
data
.
affectedRows
;
}
return
result
;
};
Query
.
prototype
.
formatError
=
function
(
err
)
{
var
match
;
...
...
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