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 4a717db1
authored
Jul 25, 2010
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor bugfixing + some refactoring
1 parent
ab9055fa
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
25 deletions
src/Sequelize.js
src/SequelizeHelper.js
src/SequelizeTable.js
src/Sequelize.js
View file @
4a717db
...
...
@@ -48,28 +48,25 @@ var classMethods = {
}
}
var
instanceMethods
=
{
asTableName
:
function
(
name
)
{
return
name
+
"s"
Sequelize
.
prototype
=
{
get
tableNames
()
{
var
result
=
[]
SequelizeHelper
.
Hash
.
keys
(
this
.
tables
).
forEach
(
function
(
tableName
)
{
result
.
push
(
SequelizeHelper
.
SQL
.
asTableName
(
tableName
))
})
return
result
},
define
:
function
(
name
,
attributes
)
{
var
table
=
new
SequelizeTable
(
this
,
this
.
asTableName
(
name
),
attributes
)
var
table
=
new
SequelizeTable
(
this
,
SequelizeHelper
.
SQL
.
asTableName
(
name
),
attributes
)
table
.
attributes
=
attributes
this
.
tables
[
name
]
=
{
constructor
:
table
,
attributes
:
attributes
}
table
.
sequelize
=
this
return
table
},
get
tableNames
()
{
var
result
=
[]
var
self
=
this
SequelizeHelper
.
Hash
.
keys
(
this
.
tables
).
forEach
(
function
(
tableName
)
{
result
.
push
(
self
.
asTableName
(
tableName
))
})
return
result
},
query
:
function
(
queryString
,
callback
)
{
var
fields
=
[]
var
values
=
[]
...
...
@@ -104,8 +101,4 @@ var instanceMethods = {
SequelizeHelper
.
Hash
.
forEach
(
classMethods
,
function
(
method
,
methodName
)
{
Sequelize
[
methodName
]
=
method
})
SequelizeHelper
.
Hash
.
forEach
(
instanceMethods
,
function
(
method
,
methodName
)
{
Sequelize
.
prototype
[
methodName
]
=
method
})
\ No newline at end of file
src/SequelizeHelper.js
View file @
4a717db
...
...
@@ -5,6 +5,10 @@ SequelizeHelper = {
},
SQL
:
{
asTableName
:
function
(
name
)
{
return
name
+
"s"
},
valuesForInsertQuery
:
function
(
object
)
{
var
actualValues
=
object
.
values
,
result
=
[]
...
...
src/SequelizeTable.js
View file @
4a717db
...
...
@@ -63,19 +63,22 @@ SequelizeTable = function(sequelize, tableName, attributes) {
}
// instance methods
var
instanceMethods
=
{
table
.
prototype
=
{
get
values
()
{
var
result
=
{}
var
self
=
this
SequelizeHelper
.
Hash
.
keys
(
attributes
).
forEach
(
function
(
attribute
)
{
result
[
attribute
]
=
self
[
attribute
]
})
return
result
},
save
:
function
(
callback
)
{
var
query
=
null
var
self
=
this
if
(
this
.
id
==
null
)
query
=
Sequelize
.
sqlQueryFor
(
'insert'
,
{
table
:
this
.
tableName
,
fields
:
SequelizeHelper
.
SQL
.
fieldsForInsertQuery
(
this
),
values
:
SequelizeHelper
.
SQL
.
valuesForInsertQuery
(
this
)
...
...
@@ -86,7 +89,6 @@ SequelizeTable = function(sequelize, tableName, attributes) {
sequelize
.
query
(
query
,
function
()
{
if
(
self
.
id
==
null
)
{
table
.
find
(
self
.
values
,
function
(
result
)
{
SequelizeHelper
.
log
(
result
)
self
.
id
=
result
.
id
if
(
callback
)
callback
(
self
)
})
...
...
@@ -116,10 +118,6 @@ SequelizeTable = function(sequelize, tableName, attributes) {
SequelizeHelper
.
Hash
.
forEach
(
classMethods
,
function
(
method
,
methodName
)
{
table
[
methodName
]
=
method
})
SequelizeHelper
.
Hash
.
forEach
(
instanceMethods
,
function
(
method
,
methodName
)
{
table
.
prototype
[
methodName
]
=
method
})
return
table
}
\ No newline at end of file
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