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 f1d08764
authored
Apr 19, 2020
by
Andy Edwards
Committed by
GitHub
Apr 19, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(query-interface): asyncify methods (#12126)
1 parent
39c35012
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
55 deletions
lib/query-interface.js
test/integration/dialects/postgres/query-interface.test.js
test/integration/query-interface.test.js
lib/query-interface.js
View file @
f1d0876
This diff is collapsed.
Click to expand it.
test/integration/dialects/postgres/query-interface.test.js
View file @
f1d0876
...
...
@@ -128,34 +128,28 @@ if (dialect.match(/^postgres/)) {
return
Promise
.
all
([
// requires functionName
expect
(()
=>
{
return
this
.
queryInterface
.
createFunction
(
null
,
[{
name
:
'test'
}],
'integer'
,
'plpgsql'
,
body
,
options
);
}).
to
.
throw
(
/createFunction missing some parameters. Did you pass functionName, returnType, language and body/
),
expect
(
this
.
queryInterface
.
createFunction
(
null
,
[{
name
:
'test'
}],
'integer'
,
'plpgsql'
,
body
,
options
))
.
to
.
be
.
rejectedWith
(
/createFunction missing some parameters. Did you pass functionName, returnType, language and body/
),
// requires Parameters array
expect
(()
=>
{
return
this
.
queryInterface
.
createFunction
(
'create_job'
,
null
,
'integer'
,
'plpgsql'
,
body
,
options
);
}).
to
.
throw
(
/function parameters array required/
),
expect
(
this
.
queryInterface
.
createFunction
(
'create_job'
,
null
,
'integer'
,
'plpgsql'
,
body
,
options
))
.
to
.
be
.
rejectedWith
(
/function parameters array required/
),
// requires returnType
expect
(()
=>
{
return
this
.
queryInterface
.
createFunction
(
'create_job'
,
[{
type
:
'varchar'
,
name
:
'test'
}],
null
,
'plpgsql'
,
body
,
options
);
}).
to
.
throw
(
/createFunction missing some parameters. Did you pass functionName, returnType, language and body/
),
expect
(
this
.
queryInterface
.
createFunction
(
'create_job'
,
[{
type
:
'varchar'
,
name
:
'test'
}],
null
,
'plpgsql'
,
body
,
options
))
.
to
.
be
.
rejectedWith
(
/createFunction missing some parameters. Did you pass functionName, returnType, language and body/
),
// requires type in parameter array
expect
(()
=>
{
return
this
.
queryInterface
.
createFunction
(
'create_job'
,
[{
name
:
'test'
}],
'integer'
,
'plpgsql'
,
body
,
options
);
}).
to
.
throw
(
/function or trigger used with a parameter without any type/
),
expect
(
this
.
queryInterface
.
createFunction
(
'create_job'
,
[{
name
:
'test'
}],
'integer'
,
'plpgsql'
,
body
,
options
))
.
to
.
be
.
rejectedWith
(
/function or trigger used with a parameter without any type/
),
// requires language
expect
(()
=>
{
return
this
.
queryInterface
.
createFunction
(
'create_job'
,
[{
type
:
'varchar'
,
name
:
'test'
}],
'varchar'
,
null
,
body
,
options
);
}).
to
.
throw
(
/createFunction missing some parameters. Did you pass functionName, returnType, language and body/
),
expect
(
this
.
queryInterface
.
createFunction
(
'create_job'
,
[{
type
:
'varchar'
,
name
:
'test'
}],
'varchar'
,
null
,
body
,
options
))
.
to
.
be
.
rejectedWith
(
/createFunction missing some parameters. Did you pass functionName, returnType, language and body/
),
// requires body
expect
(()
=>
{
return
this
.
queryInterface
.
createFunction
(
'create_job'
,
[{
type
:
'varchar'
,
name
:
'test'
}],
'varchar'
,
'plpgsql'
,
null
,
options
);
}).
to
.
throw
(
/createFunction missing some parameters. Did you pass functionName, returnType, language and body/
)
expect
(
this
.
queryInterface
.
createFunction
(
'create_job'
,
[{
type
:
'varchar'
,
name
:
'test'
}],
'varchar'
,
'plpgsql'
,
null
,
options
))
.
to
.
be
.
rejectedWith
(
/createFunction missing some parameters. Did you pass functionName, returnType, language and body/
)
]);
});
...
...
@@ -176,20 +170,14 @@ if (dialect.match(/^postgres/)) {
it
(
'produces an error when options.variables is missing expected parameters'
,
function
()
{
const
body
=
'return 1;'
;
expect
(()
=>
{
const
options
=
{
variables
:
100
};
return
this
.
queryInterface
.
createFunction
(
'test_func'
,
[],
'integer'
,
'plpgsql'
,
body
,
[],
options
);
}).
to
.
throw
(
/expandFunctionVariableList: function variables must be an array/
);
expect
(()
=>
{
const
options
=
{
variables
:
[{
name
:
'myVar'
}]
};
return
this
.
queryInterface
.
createFunction
(
'test_func'
,
[],
'integer'
,
'plpgsql'
,
body
,
[],
options
);
}).
to
.
throw
(
/function variable must have a name and type/
);
expect
(()
=>
{
const
options
=
{
variables
:
[{
type
:
'integer'
}]
};
return
this
.
queryInterface
.
createFunction
(
'test_func'
,
[],
'integer'
,
'plpgsql'
,
body
,
[],
options
);
}).
to
.
throw
(
/function variable must have a name and type/
);
expect
(
this
.
queryInterface
.
createFunction
(
'test_func'
,
[],
'integer'
,
'plpgsql'
,
body
,
[],
{
variables
:
100
}))
.
to
.
be
.
rejectedWith
(
/expandFunctionVariableList: function variables must be an array/
);
expect
(
this
.
queryInterface
.
createFunction
(
'test_func'
,
[],
'integer'
,
'plpgsql'
,
body
,
[],
{
variables
:
[{
name
:
'myVar'
}]
}))
.
to
.
be
.
rejectedWith
(
/function variable must have a name and type/
);
expect
(
this
.
queryInterface
.
createFunction
(
'test_func'
,
[],
'integer'
,
'plpgsql'
,
body
,
[],
{
variables
:
[{
type
:
'integer'
}]
}))
.
to
.
be
.
rejectedWith
(
/function variable must have a name and type/
);
});
it
(
'uses declared variables'
,
function
()
{
...
...
@@ -229,17 +217,14 @@ if (dialect.match(/^postgres/)) {
it
(
'produces an error when missing expected parameters'
,
function
()
{
return
Promise
.
all
([
expect
(()
=>
{
return
this
.
queryInterface
.
dropFunction
();
}).
to
.
throw
(
/.*requires functionName/
),
expect
(
this
.
queryInterface
.
dropFunction
())
.
to
.
be
.
rejectedWith
(
/.*requires functionName/
),
expect
(()
=>
{
return
this
.
queryInterface
.
dropFunction
(
'droptest'
);
}).
to
.
throw
(
/.*function parameters array required/
),
expect
(
this
.
queryInterface
.
dropFunction
(
'droptest'
))
.
to
.
be
.
rejectedWith
(
/.*function parameters array required/
),
expect
(()
=>
{
return
this
.
queryInterface
.
dropFunction
(
'droptest'
,
[{
name
:
'test'
}]);
}).
to
.
be
.
throw
(
/.*function or trigger used with a parameter without any type/
)
expect
(
this
.
queryInterface
.
dropFunction
(
'droptest'
,
[{
name
:
'test'
}]))
.
to
.
be
.
rejectedWith
(
/.*function or trigger used with a parameter without any type/
)
]);
});
});
...
...
test/integration/query-interface.test.js
View file @
f1d0876
...
...
@@ -339,16 +339,12 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
}
});
const
testArgs
=
(...
args
)
=>
{
expect
(()
=>
{
this
.
queryInterface
.
addColumn
(...
args
);
throw
new
Error
(
'Did not throw immediately...'
);
}).
to
.
throw
(
Error
,
'addColumn takes at least 3 arguments (table, attribute name, attribute definition)'
);
};
const
testArgs
=
(...
args
)
=>
expect
(
this
.
queryInterface
.
addColumn
(...
args
))
.
to
.
be
.
rejectedWith
(
Error
,
'addColumn takes at least 3 arguments (table, attribute name, attribute definition)'
);
testArgs
(
'users'
,
'level_id'
);
testArgs
(
null
,
'level_id'
);
testArgs
(
'users'
,
null
,
{});
await
testArgs
(
'users'
,
'level_id'
);
await
testArgs
(
null
,
'level_id'
);
await
testArgs
(
'users'
,
null
,
{});
});
it
(
'should work with schemas'
,
async
function
()
{
...
...
@@ -539,14 +535,13 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
expect
(
constraints
).
to
.
not
.
include
(
'check_user_roles'
);
});
it
(
'addconstraint missing type'
,
function
()
{
expect
(()
=>
{
it
(
'addconstraint missing type'
,
async
function
()
{
await
expect
(
this
.
queryInterface
.
addConstraint
(
'users'
,
[
'roles'
],
{
where
:
{
roles
:
[
'user'
,
'admin'
,
'guest'
,
'moderator'
]
},
name
:
'check_user_roles'
});
throw
new
Error
(
'Did not throw immediately...'
);
}).
to
.
throw
(
Error
,
'Constraint type must be specified through options.type'
);
})
).
to
.
be
.
rejectedWith
(
Error
,
'Constraint type must be specified through options.type'
);
});
});
}
...
...
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