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 b52f6295
authored
Dec 07, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add databaseVersion() method for getting the dialect database version
1 parent
5aef119f
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
49 additions
and
1 deletions
lib/dialects/abstract/query-generator.js
lib/dialects/abstract/query.js
lib/dialects/mysql/query-generator.js
lib/dialects/mysql/query.js
lib/dialects/postgres/query-generator.js
lib/dialects/postgres/query.js
lib/dialects/sqlite/query-generator.js
lib/dialects/sqlite/query.js
lib/query-interface.js
lib/query-types.js
lib/sequelize.js
test/sequelize.test.js
lib/dialects/abstract/query-generator.js
View file @
b52f629
...
...
@@ -50,6 +50,10 @@ module.exports = (function() {
throwMethodUndefined
(
'createTableQuery'
);
},
versionQuery
:
function
(
tableName
,
attributes
,
options
)
{
throwMethodUndefined
(
'versionQuery'
);
},
describeTableQuery
:
function
(
tableName
,
schema
,
schemaDelimiter
)
{
var
table
=
this
.
quoteTable
(
this
.
addSchema
({
...
...
lib/dialects/abstract/query.js
View file @
b52f629
...
...
@@ -83,6 +83,10 @@ module.exports = (function() {
}
};
AbstractQuery
.
prototype
.
isVersionQuery
=
function
()
{
return
this
.
options
.
type
===
QueryTypes
.
VERSION
;
};
AbstractQuery
.
prototype
.
isUpsertQuery
=
function
()
{
return
this
.
options
.
type
===
QueryTypes
.
UPSERT
;
};
...
...
lib/dialects/mysql/query-generator.js
View file @
b52f629
...
...
@@ -17,6 +17,10 @@ module.exports = (function() {
return
'SHOW TABLES'
;
},
versionQuery
:
function
()
{
return
'SELECT VERSION() as `version`'
;
},
createTableQuery
:
function
(
tableName
,
attributes
,
options
)
{
options
=
Utils
.
_
.
extend
({
engine
:
'InnoDB'
,
...
...
lib/dialects/mysql/query.js
View file @
b52f629
...
...
@@ -97,6 +97,8 @@ module.exports = (function() {
result
=
data
[
0
];
}
else
if
(
this
.
isBulkUpdateQuery
()
||
this
.
isBulkDeleteQuery
()
||
this
.
isUpsertQuery
())
{
result
=
data
.
affectedRows
;
}
else
if
(
this
.
isVersionQuery
())
{
result
=
data
[
0
].
version
;
}
return
result
;
...
...
lib/dialects/postgres/query-generator.js
View file @
b52f629
...
...
@@ -28,6 +28,10 @@ module.exports = (function() {
return
"SELECT schema_name FROM information_schema.schemata WHERE schema_name <> 'information_schema' AND schema_name != 'public' AND schema_name !~ E'^pg_';"
;
},
versionQuery
:
function
()
{
return
'SELECT VERSION() as "version"'
;
},
createTableQuery
:
function
(
tableName
,
attributes
,
options
)
{
var
self
=
this
;
...
...
lib/dialects/postgres/query.js
View file @
b52f629
...
...
@@ -234,6 +234,8 @@ module.exports = (function() {
}
return
self
.
callee
||
(
rows
&&
rows
[
0
])
||
undefined
;
}
else
if
(
self
.
isVersionQuery
())
{
return
results
[
0
].
version
;
}
else
{
return
results
;
}
...
...
lib/dialects/sqlite/query-generator.js
View file @
b52f629
...
...
@@ -28,6 +28,10 @@ module.exports = (function() {
return
"SELECT name FROM `sqlite_master` WHERE type='table' and name!='sqlite_sequence';"
;
},
versionQuery
:
function
()
{
return
"SELECT sqlite_version() as `version`"
;
},
createTableQuery
:
function
(
tableName
,
attributes
,
options
)
{
options
=
options
||
{};
...
...
lib/dialects/sqlite/query.js
View file @
b52f629
...
...
@@ -137,6 +137,8 @@ module.exports = (function() {
result
=
metaData
.
changes
;
}
else
if
(
self
.
options
.
type
===
QueryTypes
.
UPSERT
)
{
result
=
undefined
;
}
else
if
(
self
.
options
.
type
===
QueryTypes
.
VERSION
)
{
result
=
results
[
0
].
version
;
}
resolve
(
result
);
...
...
lib/query-interface.js
View file @
b52f629
...
...
@@ -61,6 +61,13 @@ module.exports = (function() {
});
};
QueryInterface
.
prototype
.
databaseVersion
=
function
()
{
return
this
.
sequelize
.
query
(
this
.
QueryGenerator
.
versionQuery
(),
null
,
{
raw
:
true
,
type
:
QueryTypes
.
VERSION
});
};
QueryInterface
.
prototype
.
createTable
=
function
(
tableName
,
attributes
,
options
)
{
var
keys
=
Object
.
keys
(
attributes
)
,
keyLen
=
keys
.
length
...
...
lib/query-types.js
View file @
b52f629
...
...
@@ -6,4 +6,5 @@ module.exports = {
BULKUPDATE
:
'BULKUPDATE'
,
BULKDELETE
:
'BULKDELETE'
,
UPSERT
:
'UPSERT'
,
VERSION
:
'VERSION'
};
lib/sequelize.js
View file @
b52f629
...
...
@@ -787,6 +787,10 @@ module.exports = (function() {
});
};
Sequelize
.
prototype
.
databaseVersion
=
function
()
{
return
this
.
queryInterface
.
databaseVersion
();
};
Sequelize
.
prototype
.
validate
=
Sequelize
.
prototype
.
authenticate
;
/**
...
...
test/sequelize.test.js
View file @
b52f629
...
...
@@ -1118,4 +1118,13 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
})
}
})
})
describe
(
'databaseVersion'
,
function
()
{
it
(
'should database/dialect version'
,
function
()
{
return
this
.
sequelize
.
databaseVersion
().
then
(
function
(
version
)
{
expect
(
typeof
version
).
to
.
equal
(
'string'
);
expect
(
version
).
to
.
be
.
ok
;
});
});
});
});
\ 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