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 = {
...
@@ -48,28 +48,25 @@ var classMethods = {
}
}
}
}
var
instanceMethods
=
{
Sequelize
.
prototype
=
{
asTableName
:
function
(
name
)
{
get
tableNames
()
{
return
name
+
"s"
var
result
=
[]
SequelizeHelper
.
Hash
.
keys
(
this
.
tables
).
forEach
(
function
(
tableName
)
{
result
.
push
(
SequelizeHelper
.
SQL
.
asTableName
(
tableName
))
})
return
result
},
},
define
:
function
(
name
,
attributes
)
{
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
table
.
attributes
=
attributes
this
.
tables
[
name
]
=
{
constructor
:
table
,
attributes
:
attributes
}
this
.
tables
[
name
]
=
{
constructor
:
table
,
attributes
:
attributes
}
table
.
sequelize
=
this
table
.
sequelize
=
this
return
table
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
)
{
query
:
function
(
queryString
,
callback
)
{
var
fields
=
[]
var
fields
=
[]
var
values
=
[]
var
values
=
[]
...
@@ -104,8 +101,4 @@ var instanceMethods = {
...
@@ -104,8 +101,4 @@ var instanceMethods = {
SequelizeHelper
.
Hash
.
forEach
(
classMethods
,
function
(
method
,
methodName
)
{
SequelizeHelper
.
Hash
.
forEach
(
classMethods
,
function
(
method
,
methodName
)
{
Sequelize
[
methodName
]
=
method
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 = {
...
@@ -5,6 +5,10 @@ SequelizeHelper = {
},
},
SQL
:
{
SQL
:
{
asTableName
:
function
(
name
)
{
return
name
+
"s"
},
valuesForInsertQuery
:
function
(
object
)
{
valuesForInsertQuery
:
function
(
object
)
{
var
actualValues
=
object
.
values
,
var
actualValues
=
object
.
values
,
result
=
[]
result
=
[]
...
...
src/SequelizeTable.js
View file @
4a717db
...
@@ -63,19 +63,22 @@ SequelizeTable = function(sequelize, tableName, attributes) {
...
@@ -63,19 +63,22 @@ SequelizeTable = function(sequelize, tableName, attributes) {
}
}
// instance methods
// instance methods
var
instanceMethods
=
{
table
.
prototype
=
{
get
values
()
{
get
values
()
{
var
result
=
{}
var
result
=
{}
var
self
=
this
var
self
=
this
SequelizeHelper
.
Hash
.
keys
(
attributes
).
forEach
(
function
(
attribute
)
{
SequelizeHelper
.
Hash
.
keys
(
attributes
).
forEach
(
function
(
attribute
)
{
result
[
attribute
]
=
self
[
attribute
]
result
[
attribute
]
=
self
[
attribute
]
})
})
return
result
return
result
},
},
save
:
function
(
callback
)
{
save
:
function
(
callback
)
{
var
query
=
null
var
query
=
null
var
self
=
this
var
self
=
this
if
(
this
.
id
==
null
)
if
(
this
.
id
==
null
)
query
=
Sequelize
.
sqlQueryFor
(
'insert'
,
{
query
=
Sequelize
.
sqlQueryFor
(
'insert'
,
{
table
:
this
.
tableName
,
fields
:
SequelizeHelper
.
SQL
.
fieldsForInsertQuery
(
this
),
values
:
SequelizeHelper
.
SQL
.
valuesForInsertQuery
(
this
)
table
:
this
.
tableName
,
fields
:
SequelizeHelper
.
SQL
.
fieldsForInsertQuery
(
this
),
values
:
SequelizeHelper
.
SQL
.
valuesForInsertQuery
(
this
)
...
@@ -86,7 +89,6 @@ SequelizeTable = function(sequelize, tableName, attributes) {
...
@@ -86,7 +89,6 @@ SequelizeTable = function(sequelize, tableName, attributes) {
sequelize
.
query
(
query
,
function
()
{
sequelize
.
query
(
query
,
function
()
{
if
(
self
.
id
==
null
)
{
if
(
self
.
id
==
null
)
{
table
.
find
(
self
.
values
,
function
(
result
)
{
table
.
find
(
self
.
values
,
function
(
result
)
{
SequelizeHelper
.
log
(
result
)
self
.
id
=
result
.
id
self
.
id
=
result
.
id
if
(
callback
)
callback
(
self
)
if
(
callback
)
callback
(
self
)
})
})
...
@@ -116,10 +118,6 @@ SequelizeTable = function(sequelize, tableName, attributes) {
...
@@ -116,10 +118,6 @@ SequelizeTable = function(sequelize, tableName, attributes) {
SequelizeHelper
.
Hash
.
forEach
(
classMethods
,
function
(
method
,
methodName
)
{
SequelizeHelper
.
Hash
.
forEach
(
classMethods
,
function
(
method
,
methodName
)
{
table
[
methodName
]
=
method
table
[
methodName
]
=
method
})
})
SequelizeHelper
.
Hash
.
forEach
(
instanceMethods
,
function
(
method
,
methodName
)
{
table
.
prototype
[
methodName
]
=
method
})
return
table
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