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 e7c8f265
authored
Sep 12, 2013
by
Andre Cerqueira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support for relative paths on sequelize.import
1 parent
a8ce9570
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
1 deletions
lib/sequelize.js
lib/utils.js
test/sequelize.test.js
lib/sequelize.js
View file @
e7c8f26
...
@@ -215,6 +215,13 @@ module.exports = (function() {
...
@@ -215,6 +215,13 @@ module.exports = (function() {
}
}
Sequelize
.
prototype
.
import
=
function
(
path
)
{
Sequelize
.
prototype
.
import
=
function
(
path
)
{
// is it a relative path?
if
(
url
.
parse
(
path
).
pathname
.
indexOf
(
'/'
)
!==
0
)
{
// make path relative to the caller
var
callerFilename
=
Utils
.
stack
()[
1
].
getFileName
();
path
=
url
.
resolve
(
callerFilename
,
path
);
}
if
(
!
this
.
importCache
[
path
])
{
if
(
!
this
.
importCache
[
path
])
{
var
defineCall
=
require
(
path
)
var
defineCall
=
require
(
path
)
this
.
importCache
[
path
]
=
defineCall
(
this
,
DataTypes
)
this
.
importCache
[
path
]
=
defineCall
(
this
,
DataTypes
)
...
...
lib/utils.js
View file @
e7c8f26
...
@@ -451,6 +451,18 @@ var Utils = module.exports = {
...
@@ -451,6 +451,18 @@ var Utils = module.exports = {
return
subClass
;
return
subClass
;
},
},
stack
:
function
()
{
var
orig
=
Error
.
prepareStackTrace
;
Error
.
prepareStackTrace
=
function
(
_
,
stack
){
return
stack
;
};
var
err
=
new
Error
();
Error
.
captureStackTrace
(
err
,
arguments
.
callee
);
var
stack
=
err
.
stack
;
Error
.
prepareStackTrace
=
orig
;
return
stack
;
},
now
:
function
(
dialect
)
{
now
:
function
(
dialect
)
{
var
now
=
new
Date
()
var
now
=
new
Date
()
if
(
dialect
!=
"postgres"
)
now
.
setMilliseconds
(
0
)
if
(
dialect
!=
"postgres"
)
now
.
setMilliseconds
(
0
)
...
...
test/sequelize.test.js
View file @
e7c8f26
...
@@ -375,11 +375,17 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
...
@@ -375,11 +375,17 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
})
})
describe
(
'import'
,
function
()
{
describe
(
'import'
,
function
()
{
it
(
"imports a dao definition from a file"
,
function
(
done
)
{
it
(
"imports a dao definition from a file
absolute path
"
,
function
(
done
)
{
var
Project
=
this
.
sequelize
.
import
(
__dirname
+
"/assets/project"
)
var
Project
=
this
.
sequelize
.
import
(
__dirname
+
"/assets/project"
)
expect
(
Project
).
to
.
exist
expect
(
Project
).
to
.
exist
done
()
done
()
})
})
it
(
"imports a dao definition from a file relative path"
,
function
(
done
)
{
var
Project
=
this
.
sequelize
.
import
(
"assets/project"
)
expect
(
Project
).
to
.
exist
done
()
})
})
})
describe
(
'define'
,
function
()
{
describe
(
'define'
,
function
()
{
...
...
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