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 31113cec
authored
Jul 14, 2018
by
Tommy Montgomery
Committed by
Sushant
Jul 14, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: allow querying sqlite_master table (#9645)
1 parent
b6c2e421
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
10 deletions
lib/dialects/sqlite/query-interface.js
lib/dialects/sqlite/query.js
test/integration/data-types.test.js
test/integration/dialects/sqlite/sqlite-master.test.js
lib/dialects/sqlite/query-interface.js
View file @
31113ce
...
...
@@ -3,6 +3,7 @@
const
_
=
require
(
'lodash'
);
const
Promise
=
require
(
'../../promise'
);
const
sequelizeErrors
=
require
(
'../../errors'
);
const
QueryTypes
=
require
(
'../../query-types'
);
/**
Returns an object that treats SQLite's inabilities to do certain queries.
...
...
@@ -152,7 +153,7 @@ function addConstraint(tableName, options) {
const
describeCreateTableSql
=
this
.
QueryGenerator
.
describeCreateTableQuery
(
tableName
);
let
createTableSql
;
return
this
.
sequelize
.
query
(
describeCreateTableSql
,
options
)
return
this
.
sequelize
.
query
(
describeCreateTableSql
,
_
.
assign
({},
options
,
{
type
:
QueryTypes
.
SELECT
,
raw
:
true
})
)
.
then
(
constraints
=>
{
const
sql
=
constraints
[
0
].
sql
;
const
index
=
sql
.
length
-
1
;
...
...
lib/dialects/sqlite/query.js
View file @
31113ce
...
...
@@ -144,14 +144,12 @@ class Query extends AbstractQuery {
}
}
if
(
query
.
sql
.
indexOf
(
'sqlite_master'
)
!==
-
1
)
{
if
(
query
.
sql
.
indexOf
(
'SELECT sql FROM sqlite_master WHERE tbl_name'
)
!==
-
1
)
{
result
=
results
;
if
(
result
&&
result
[
0
]
&&
result
[
0
].
sql
.
indexOf
(
'CONSTRAINT'
)
!==
-
1
)
{
result
=
query
.
parseConstraintsFromSql
(
results
[
0
].
sql
);
}
}
else
{
result
=
results
.
map
(
resultSet
=>
resultSet
.
name
);
if
(
query
.
isShowTablesQuery
())
{
result
=
results
.
map
(
row
=>
row
.
name
);
}
else
if
(
query
.
isShowConstraintsQuery
())
{
result
=
results
;
if
(
results
&&
results
[
0
]
&&
results
[
0
].
sql
)
{
result
=
query
.
parseConstraintsFromSql
(
results
[
0
].
sql
);
}
}
else
if
(
query
.
isSelectQuery
())
{
if
(
!
query
.
options
.
raw
)
{
...
...
test/integration/data-types.test.js
View file @
31113ce
...
...
@@ -639,7 +639,10 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => {
return
record
.
reload
();
}).
then
(
record
=>
{
expect
(
typeof
record
.
stamp
).
to
.
be
.
eql
(
'string'
);
expect
(
new
Date
(
record
.
stamp
)).
to
.
equalDate
(
newDate
);
const
recordDate
=
new
Date
(
record
.
stamp
);
expect
(
recordDate
.
getUTCFullYear
()).
to
.
equal
(
newDate
.
getUTCFullYear
());
expect
(
recordDate
.
getUTCDate
()).
to
.
equal
(
newDate
.
getUTCDate
());
expect
(
recordDate
.
getUTCMonth
()).
to
.
equal
(
newDate
.
getUTCMonth
());
});
});
...
...
test/integration/dialects/sqlite/sqlite-master.test.js
0 → 100644
View file @
31113ce
'use strict'
;
const
chai
=
require
(
'chai'
),
expect
=
chai
.
expect
,
Support
=
require
(
__dirname
+
'/../../support'
),
dialect
=
Support
.
getTestDialect
(),
DataTypes
=
require
(
__dirname
+
'/../../../../lib/data-types'
);
if
(
dialect
===
'sqlite'
)
{
describe
(
'[SQLITE Specific] sqlite_master raw queries'
,
()
=>
{
beforeEach
(
function
()
{
this
.
sequelize
.
define
(
'SomeTable'
,
{
someColumn
:
DataTypes
.
INTEGER
},
{
freezeTableName
:
true
,
timestamps
:
false
});
return
this
.
sequelize
.
sync
({
force
:
true
});
});
it
(
'should be able to select with tbl_name filter'
,
function
()
{
return
this
.
sequelize
.
query
(
'SELECT * FROM sqlite_master WHERE tbl_name=\'SomeTable\''
)
.
then
(
result
=>
{
const
rows
=
result
[
0
];
expect
(
rows
).
to
.
have
.
length
(
1
);
const
row
=
rows
[
0
];
expect
(
row
).
to
.
have
.
property
(
'type'
,
'table'
);
expect
(
row
).
to
.
have
.
property
(
'name'
,
'SomeTable'
);
expect
(
row
).
to
.
have
.
property
(
'tbl_name'
,
'SomeTable'
);
expect
(
row
).
to
.
have
.
property
(
'sql'
);
});
});
it
(
'should be able to select *'
,
function
()
{
return
this
.
sequelize
.
query
(
'SELECT * FROM sqlite_master'
)
.
then
(
result
=>
{
const
rows
=
result
[
0
];
expect
(
rows
).
to
.
have
.
length
(
2
);
rows
.
forEach
(
row
=>
{
expect
(
row
).
to
.
have
.
property
(
'type'
);
expect
(
row
).
to
.
have
.
property
(
'name'
);
expect
(
row
).
to
.
have
.
property
(
'tbl_name'
);
expect
(
row
).
to
.
have
.
property
(
'rootpage'
);
expect
(
row
).
to
.
have
.
property
(
'sql'
);
});
});
});
it
(
'should be able to select just "sql" column and get rows back'
,
function
()
{
return
this
.
sequelize
.
query
(
'SELECT sql FROM sqlite_master WHERE tbl_name=\'SomeTable\''
)
.
then
(
result
=>
{
const
rows
=
result
[
0
];
expect
(
rows
).
to
.
have
.
length
(
1
);
const
row
=
rows
[
0
];
expect
(
row
).
to
.
have
.
property
(
'sql'
,
'CREATE TABLE `SomeTable` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `someColumn` INTEGER)'
);
});
});
});
}
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