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 19693357
authored
Feb 26, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into refactorings/eager_loading
2 parents
f6be85b8
b37f5ff5
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
149 additions
and
11 deletions
changelog.md
lib/SqlString.js
lib/dialects/mysql/connector-manager.js
lib/migrator.js
lib/sequelize.js
lib/utils.js
package.json
changelog.md
View file @
1969335
...
...
@@ -28,6 +28,7 @@
-
[
FEATURE
]
allow definition of a models table name (thanks to slamkajs)
-
[
FEATURE
]
allow usage of enums. #440 (thanks to KevinMartin)
-
[
FEATURE
]
allows updateAttributes to target specific fields only (thanks to Pasvaz)
-
[
DEPENDENCIES
]
mysql is now an optional dependency
# v1.5.0 #
-
[
REFACTORING
]
use underscore functions for Utils.isHash (thanks to Mick-Hansen/innofluence)
...
...
lib/SqlString.js
0 → 100644
View file @
1969335
var
SqlString
=
exports
;
SqlString
.
escapeId
=
function
(
val
,
forbidQualified
)
{
if
(
forbidQualified
)
{
return
'`'
+
val
.
replace
(
/`/g
,
'``'
)
+
'`'
;
}
return
'`'
+
val
.
replace
(
/`/g
,
'``'
).
replace
(
/
\.
/g
,
'`.`'
)
+
'`'
;
};
SqlString
.
escape
=
function
(
val
,
stringifyObjects
,
timeZone
)
{
if
(
val
===
undefined
||
val
===
null
)
{
return
'NULL'
;
}
switch
(
typeof
val
)
{
case
'boolean'
:
return
(
val
)
?
'true'
:
'false'
;
case
'number'
:
return
val
+
''
;
}
if
(
val
instanceof
Date
)
{
val
=
SqlString
.
dateToString
(
val
,
timeZone
||
"Z"
);
}
if
(
Buffer
.
isBuffer
(
val
))
{
return
SqlString
.
bufferToString
(
val
);
}
if
(
Array
.
isArray
(
val
))
{
return
SqlString
.
arrayToList
(
val
,
timeZone
);
}
if
(
typeof
val
===
'object'
)
{
if
(
stringifyObjects
)
{
val
=
val
.
toString
();
}
else
{
return
SqlString
.
objectToValues
(
val
,
timeZone
);
}
}
val
=
val
.
replace
(
/
[\0\n\r\b\t\\\'\"\x
1a
]
/g
,
function
(
s
)
{
switch
(
s
)
{
case
"\0"
:
return
"\\0"
;
case
"\n"
:
return
"\\n"
;
case
"\r"
:
return
"\\r"
;
case
"\b"
:
return
"\\b"
;
case
"\t"
:
return
"\\t"
;
case
"\x1a"
:
return
"\\Z"
;
default
:
return
"\\"
+
s
;
}
});
return
"'"
+
val
+
"'"
;
};
SqlString
.
arrayToList
=
function
(
array
,
timeZone
)
{
return
array
.
map
(
function
(
v
)
{
if
(
Array
.
isArray
(
v
))
return
'('
+
SqlString
.
arrayToList
(
v
)
+
')'
;
return
SqlString
.
escape
(
v
,
true
,
timeZone
);
}).
join
(
', '
);
};
SqlString
.
format
=
function
(
sql
,
values
,
timeZone
)
{
values
=
[].
concat
(
values
);
return
sql
.
replace
(
/
\?
/g
,
function
(
match
)
{
if
(
!
values
.
length
)
{
return
match
;
}
return
SqlString
.
escape
(
values
.
shift
(),
false
,
timeZone
);
});
};
SqlString
.
dateToString
=
function
(
date
,
timeZone
)
{
var
dt
=
new
Date
(
date
);
if
(
timeZone
!=
'local'
)
{
var
tz
=
convertTimezone
(
timeZone
);
dt
.
setTime
(
dt
.
getTime
()
+
(
dt
.
getTimezoneOffset
()
*
60000
));
if
(
tz
!==
false
)
{
dt
.
setTime
(
dt
.
getTime
()
+
(
tz
*
60000
));
}
}
var
year
=
dt
.
getFullYear
();
var
month
=
zeroPad
(
dt
.
getMonth
()
+
1
);
var
day
=
zeroPad
(
dt
.
getDate
());
var
hour
=
zeroPad
(
dt
.
getHours
());
var
minute
=
zeroPad
(
dt
.
getMinutes
());
var
second
=
zeroPad
(
dt
.
getSeconds
());
return
year
+
'-'
+
month
+
'-'
+
day
+
' '
+
hour
+
':'
+
minute
+
':'
+
second
;
};
SqlString
.
bufferToString
=
function
(
buffer
)
{
var
hex
=
''
;
try
{
hex
=
buffer
.
toString
(
'hex'
);
}
catch
(
err
)
{
// node v0.4.x does not support hex / throws unknown encoding error
for
(
var
i
=
0
;
i
<
buffer
.
length
;
i
++
)
{
var
byte
=
buffer
[
i
];
hex
+=
zeroPad
(
byte
.
toString
(
16
));
}
}
return
"X'"
+
hex
+
"'"
;
};
SqlString
.
objectToValues
=
function
(
object
,
timeZone
)
{
var
values
=
[];
for
(
var
key
in
object
)
{
var
value
=
object
[
key
];
if
(
typeof
value
===
'function'
)
{
continue
;
}
values
.
push
(
this
.
escapeId
(
key
)
+
' = '
+
SqlString
.
escape
(
value
,
true
,
timeZone
));
}
return
values
.
join
(
', '
);
};
function
zeroPad
(
number
)
{
return
(
number
<
10
)
?
'0'
+
number
:
number
;
}
function
convertTimezone
(
tz
)
{
if
(
tz
==
"Z"
)
return
0
;
var
m
=
tz
.
match
(
/
([\+\-\s])(\d\d)
:
?(\d\d)?
/
);
if
(
m
)
{
return
(
m
[
1
]
==
'-'
?
-
1
:
1
)
*
(
parseInt
(
m
[
2
],
10
)
+
((
m
[
3
]
?
parseInt
(
m
[
3
],
10
)
:
0
)
/
60
))
*
60
;
}
return
false
;
}
lib/dialects/mysql/connector-manager.js
View file @
1969335
var
mysql
=
require
(
"mysql"
)
var
mysql
,
Pooling
=
require
(
'generic-pool'
)
,
Query
=
require
(
"./query"
)
,
Utils
=
require
(
"../../utils"
)
,
without
=
function
(
arr
,
elem
)
{
return
arr
.
filter
(
function
(
e
)
{
return
e
!=
elem
})
}
try
{
mysql
=
require
(
"mysql"
)
}
catch
(
err
)
{
console
.
log
(
"You need to install mysql package manually"
);
}
module
.
exports
=
(
function
()
{
var
ConnectorManager
=
function
(
sequelize
,
config
)
{
this
.
sequelize
=
sequelize
...
...
lib/migrator.js
View file @
1969335
const
fs
=
require
(
"fs"
)
,
path
=
require
(
"path"
)
,
moment
=
require
(
"moment"
)
var
Utils
=
require
(
"./utils"
)
...
...
lib/sequelize.js
View file @
1969335
...
...
@@ -2,10 +2,9 @@ var Utils = require("./utils")
,
DAOFactory
=
require
(
"./dao-factory"
)
,
DataTypes
=
require
(
'./data-types'
)
,
DAOFactoryManager
=
require
(
"./dao-factory-manager"
)
,
Migrator
=
require
(
"./migrator"
)
,
QueryInterface
=
require
(
"./query-interface"
)
if
(
parseFloat
(
process
.
version
.
replace
(
'v'
,
''
))
<
0.6
)
{
if
(
typeof
process
!=
'undefined'
&&
parseFloat
(
process
.
version
.
replace
(
'v'
,
''
))
<
0.6
)
{
console
.
log
(
"DEPRECATION WARNING: Support for Node.JS < v0.6 will be canceled in the next minor release."
)
}
...
...
@@ -85,6 +84,7 @@ module.exports = (function() {
}
Sequelize
.
prototype
.
getMigrator
=
function
(
options
,
force
)
{
var
Migrator
=
require
(
"./migrator"
)
if
(
force
)
{
this
.
migrator
=
new
Migrator
(
this
,
options
)
}
else
{
...
...
lib/utils.js
View file @
1969335
var
mysql
=
require
(
"mysql"
)
,
connection
=
mysql
.
createConnection
({})
,
util
=
require
(
"util"
)
var
util
=
require
(
"util"
)
,
DataTypes
=
require
(
"./data-types"
)
,
SqlString
=
require
(
"./SqlString"
)
var
Utils
=
module
.
exports
=
{
_
:
(
function
()
{
...
...
@@ -44,10 +43,10 @@ var Utils = module.exports = {
return
s
.
replace
(
new
RegExp
(
Utils
.
TICK_CHAR
,
'g'
),
""
)
},
escape
:
function
(
s
)
{
return
connection
.
escape
(
s
).
replace
(
/
\\
"/g
,
'"'
)
return
SqlString
.
escape
(
s
,
true
,
"local"
).
replace
(
/
\\
"/g
,
'"'
)
},
format
:
function
(
arr
)
{
return
connection
.
format
.
apply
(
connection
,
[
arr
.
shift
(),
arr
]
)
return
SqlString
.
format
(
arr
.
shift
(),
arr
)
},
isHash
:
function
(
obj
)
{
return
Utils
.
_
.
isObject
(
obj
)
&&
!
Array
.
isArray
(
obj
);
...
...
package.json
View file @
1969335
...
...
@@ -22,11 +22,10 @@
}
],
"dependencies"
:
{
"mysql"
:
"~2.0.0-alpha3"
,
"underscore"
:
"~1.4.0"
,
"underscore.string"
:
"~2.3.0"
,
"lingo"
:
"~0.0.5"
,
"validator"
:
"0.
3
.x"
,
"validator"
:
"0.
4
.x"
,
"moment"
:
"~1.7.0"
,
"commander"
:
"~0.6.0"
,
"generic-pool"
:
"1.0.9"
...
...
@@ -34,6 +33,7 @@
"devDependencies"
:
{
"jasmine-node"
:
"1.0.17"
,
"sqlite3"
:
"~2.1.5"
,
"mysql"
:
"~2.0.0-alpha3"
,
"pg"
:
"~0.10.2"
,
"buster"
:
"~0.6.0"
,
"dox-foundation"
:
"~0.3.0"
,
...
...
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