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 f1ba2808
authored
Mar 16, 2020
by
Raphaël Ricard
Committed by
GitHub
Mar 16, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(postgres): minify include aliases over limit (#11940)
1 parent
b7396137
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
0 deletions
lib/dialects/abstract/query-generator.js
lib/dialects/postgres/query.js
test/integration/dialects/postgres/query.test.js
lib/dialects/abstract/query-generator.js
View file @
f1ba280
...
...
@@ -1144,6 +1144,7 @@ class QueryGenerator {
if
(
this
.
options
.
minifyAliases
&&
!
options
.
aliasesMapping
)
{
options
.
aliasesMapping
=
new
Map
();
options
.
aliasesByTable
=
{};
options
.
includeAliases
=
new
Map
();
}
// resolve table name options
...
...
@@ -1721,6 +1722,12 @@ class QueryGenerator {
}
}
if (this.options.minifyAliases && asRight.length > 63) {
const alias = `
%
$
{
topLevelInfo
.
options
.
includeAliases
.
size
}
`;
topLevelInfo.options.includeAliases.set(alias, asRight);
}
return {
join: include.required ? 'INNER JOIN' : include.right && this._dialect.supports['RIGHT JOIN'] ? 'RIGHT OUTER JOIN' : 'LEFT OUTER JOIN',
body: this.quoteTable(tableRight, asRight),
...
...
lib/dialects/postgres/query.js
View file @
f1ba280
...
...
@@ -53,6 +53,18 @@ class Query extends AbstractQuery {
if
(
!
_
.
isEmpty
(
this
.
options
.
searchPath
))
{
sql
=
this
.
sequelize
.
getQueryInterface
().
QueryGenerator
.
setSearchPath
(
this
.
options
.
searchPath
)
+
sql
;
}
if
(
this
.
sequelize
.
options
.
minifyAliases
&&
this
.
options
.
includeAliases
)
{
_
.
toPairs
(
this
.
options
.
includeAliases
)
// Sorting to replace the longest aliases first to prevent alias collision
.
sort
((
a
,
b
)
=>
b
[
1
].
length
-
a
[
1
].
length
)
.
forEach
(([
alias
,
original
])
=>
{
const
reg
=
new
RegExp
(
_
.
escapeRegExp
(
original
),
'g'
);
sql
=
sql
.
replace
(
reg
,
alias
);
});
}
this
.
sql
=
sql
;
const
query
=
parameters
&&
parameters
.
length
...
...
test/integration/dialects/postgres/query.test.js
View file @
f1ba280
...
...
@@ -63,5 +63,52 @@ if (dialect.match(/^postgres/)) {
expect
(
res
[
taskAlias
].
title
).
to
.
be
.
equal
(
'SuperTask'
);
});
});
it
(
'should throw due to table name being truncated'
,
()
=>
{
const
sequelize
=
Support
.
createSequelizeInstance
({
minifyAliases
:
true
});
const
User
=
sequelize
.
define
(
'user_model_name_that_is_long_for_demo_but_also_surpasses_the_character_limit'
,
{
name
:
DataTypes
.
STRING
,
email
:
DataTypes
.
STRING
},
{
tableName
:
'user'
}
);
const
Project
=
sequelize
.
define
(
'project_model_name_that_is_long_for_demo_but_also_surpasses_the_character_limit'
,
{
name
:
DataTypes
.
STRING
},
{
tableName
:
'project'
}
);
const
Company
=
sequelize
.
define
(
'company_model_name_that_is_long_for_demo_but_also_surpasses_the_character_limit'
,
{
name
:
DataTypes
.
STRING
},
{
tableName
:
'company'
}
);
User
.
hasMany
(
Project
,
{
foreignKey
:
'userId'
});
Project
.
belongsTo
(
Company
,
{
foreignKey
:
'companyId'
});
return
sequelize
.
sync
({
force
:
true
}).
then
(()
=>
{
return
Company
.
create
({
name
:
'Sequelize'
}).
then
(
comp
=>
{
return
User
.
create
({
name
:
'standard user'
}).
then
(
user
=>
{
return
Project
.
create
({
name
:
'Manhattan'
,
companyId
:
comp
.
id
,
userId
:
user
.
id
}).
then
(()
=>
{
return
User
.
findAll
({
include
:
{
model
:
Project
,
include
:
Company
}
});
});
});
});
});
});
});
}
\ 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