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 7c3df785
authored
Dec 14, 2011
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed spec + added selectQuery to sqlite
1 parent
f18ddbd1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
0 deletions
lib/connectors/sqlite/query-generator.js
spec/sqlite/model-factory.spec.js
lib/connectors/sqlite/query-generator.js
View file @
7c3df78
...
@@ -37,6 +37,38 @@ module.exports = (function() {
...
@@ -37,6 +37,38 @@ module.exports = (function() {
return
"SELECT name FROM sqlite_master WHERE type='table';"
return
"SELECT name FROM sqlite_master WHERE type='table';"
},
},
selectQuery
:
function
(
tableName
,
options
)
{
options
=
options
||
{}
options
.
table
=
Utils
.
addTicks
(
tableName
)
options
.
attributes
=
options
.
attributes
&&
options
.
attributes
.
map
(
function
(
attr
){
if
(
Array
.
isArray
(
attr
)
&&
attr
.
length
==
2
)
return
[
attr
[
0
],
Utils
.
addTicks
(
attr
[
1
])].
join
(
' as '
)
else
return
Utils
.
addTicks
(
attr
)
}).
join
(
", "
)
options
.
attributes
=
options
.
attributes
||
'*'
var
query
=
"SELECT <%= attributes %> FROM <%= table %>"
if
(
options
.
where
)
{
options
.
where
=
QueryGenerator
.
getWhereConditions
(
options
.
where
)
query
+=
" WHERE <%= where %>"
}
if
(
options
.
order
)
query
+=
" ORDER BY <%= order %>"
if
(
options
.
group
)
{
options
.
group
=
Utils
.
addTicks
(
options
.
group
)
query
+=
" GROUP BY <%= group %>"
}
if
(
options
.
limit
)
{
if
(
options
.
offset
)
query
+=
" LIMIT <%= offset %>, <%= limit %>"
else
query
+=
" LIMIT <%= limit %>"
}
query
+=
";"
return
Utils
.
_
.
template
(
query
)(
options
)
},
insertQuery
:
function
(
tableName
,
attrValueHash
)
{
insertQuery
:
function
(
tableName
,
attrValueHash
)
{
var
query
=
"INSERT INTO <%= table %> (<%= attributes %>) VALUES (<%= values %>);"
var
query
=
"INSERT INTO <%= table %> (<%= attributes %>) VALUES (<%= values %>);"
...
...
spec/sqlite/model-factory.spec.js
View file @
7c3df78
...
@@ -33,6 +33,7 @@ describe('ModelFactory', function() {
...
@@ -33,6 +33,7 @@ describe('ModelFactory', function() {
return
user
.
name
return
user
.
name
})
})
expect
(
usernames
).
toEqual
([
'John Wayne'
])
expect
(
usernames
).
toEqual
([
'John Wayne'
])
done
()
}).
error
(
function
(
err
){
console
.
log
(
err
)
})
}).
error
(
function
(
err
){
console
.
log
(
err
)
})
})
})
})
})
...
...
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