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 a8f043b8
authored
May 01, 2012
by
sdepold
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fix-sqlite-date' of
https://github.com/iizukanao/sequelize
into ii…
…zukanao-fix-sqlite-date
2 parents
c0fd2af4
b8d05967
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
6 deletions
lib/dialects/sqlite/query.js
spec-jasmine/dao.spec.js
lib/dialects/sqlite/query.js
View file @
a8f043b
...
...
@@ -31,16 +31,38 @@ module.exports = (function() {
this
.
options
.
logging
(
'Executing: '
+
this
.
sql
)
}
var
columnTypes
=
{};
this
.
database
.
serialize
(
function
()
{
var
isInsertCommand
=
(
self
.
sql
.
toLowerCase
().
indexOf
(
'insert'
)
==
0
)
,
isUpdateCommand
=
(
self
.
sql
.
toLowerCase
().
indexOf
(
'update'
)
==
0
)
,
databaseMethod
=
(
isInsertCommand
||
isUpdateCommand
)
?
'run'
:
'all'
var
executeSql
=
function
()
{
self
.
database
[
databaseMethod
](
self
.
sql
,
function
(
err
,
results
)
{
//allow clients to listen to sql to do their own logging or whatnot
self
.
emit
(
'sql'
,
self
.
sql
)
this
.
columnTypes
=
columnTypes
;
err
?
onFailure
.
call
(
self
,
err
)
:
onSuccess
.
call
(
self
,
results
,
this
)
})
};
var
isInsertCommand
=
(
self
.
sql
.
toLowerCase
().
indexOf
(
'insert'
)
==
0
)
,
isUpdateCommand
=
(
self
.
sql
.
toLowerCase
().
indexOf
(
'update'
)
==
0
)
,
databaseMethod
=
(
isInsertCommand
||
isUpdateCommand
)
?
'run'
:
'all'
if
(
databaseMethod
===
'all'
&&
/select
\s
.*
?\s
from
\s
+
([^
;
]
+
)
/i
.
test
(
self
.
sql
))
{
var
tableName
=
RegExp
.
$1
;
if
(
tableName
!==
'sqlite_master'
)
{
// get the column types
self
.
database
.
all
(
"PRAGMA table_info("
+
tableName
+
")"
,
function
(
err
,
results
)
{
if
(
!
err
)
{
for
(
var
i
=
0
,
l
=
results
.
length
;
i
<
l
;
i
++
)
{
columnTypes
[
results
[
i
].
name
]
=
results
[
i
].
type
;
}
}
executeSql
();
});
}
else
{
executeSql
();
}
}
else
{
executeSql
();
}
})
return
this
...
...
@@ -68,6 +90,11 @@ module.exports = (function() {
result
=
results
}
else
{
result
=
results
.
map
(
function
(
result
)
{
for
(
var
name
in
result
)
{
if
(
metaData
.
columnTypes
[
name
]
===
'DATETIME'
)
{
result
[
name
]
=
new
Date
(
result
[
name
]);
}
}
return
self
.
callee
.
build
(
result
,
{
isNewRecord
:
false
})
})
}
...
...
spec-jasmine/dao.spec.js
View file @
a8f043b
...
...
@@ -20,7 +20,10 @@ describe('DAO', function() {
var
setup
=
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
=
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
User
=
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
,
birthDate
:
Sequelize
.
DATE
})
User
.
sync
({
force
:
true
}).
success
(
done
)
})
}
...
...
@@ -332,7 +335,10 @@ describe('DAO', function() {
describe
(
'save'
,
function
()
{
it
(
"stores an entry in the database"
,
function
()
{
var
username
=
'user'
,
user
=
User
.
build
({
username
:
username
})
,
user
=
User
.
build
({
username
:
username
,
birthDate
:
new
Date
(
1984
,
8
,
23
)
})
Helpers
.
async
(
function
(
done
)
{
User
.
all
().
success
(
function
(
users
)
{
...
...
@@ -349,6 +355,8 @@ describe('DAO', function() {
User
.
all
().
success
(
function
(
users
)
{
expect
(
users
.
length
).
toEqual
(
1
)
expect
(
users
[
0
].
username
).
toEqual
(
username
)
expect
(
users
[
0
].
birthDate
instanceof
Date
).
toBe
(
true
)
expect
(
users
[
0
].
birthDate
.
getTime
()).
toEqual
(
new
Date
(
1984
,
8
,
23
).
getTime
())
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