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 b33d78eb
authored
Jun 25, 2021
by
JacobLey
Committed by
GitHub
Jun 25, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(typings): fix `ignoreDuplicates` option (#13220)
1 parent
6b0b532a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
11 deletions
types/lib/model.d.ts
types/test/create.ts
types/lib/model.d.ts
View file @
b33d78e
...
@@ -668,9 +668,14 @@ export interface CreateOptions<TAttributes = any> extends BuildOptions, Logging,
...
@@ -668,9 +668,14 @@ export interface CreateOptions<TAttributes = any> extends BuildOptions, Logging,
fields
?:
(
keyof
TAttributes
)[];
fields
?:
(
keyof
TAttributes
)[];
/**
/**
*
On Duplicate
*
dialect specific ON CONFLICT DO NOTHING / INSERT IGNORE
*/
*/
onDuplicate
?:
string
;
ignoreDuplicates
?:
boolean
;
/**
* Return the affected rows (only for postgres)
*/
returning
?:
boolean
|
(
keyof
TAttributes
)[];
/**
/**
* If false, validations won't be run.
* If false, validations won't be run.
...
@@ -749,7 +754,7 @@ export interface BulkCreateOptions<TAttributes = any> extends Logging, Transacti
...
@@ -749,7 +754,7 @@ export interface BulkCreateOptions<TAttributes = any> extends Logging, Transacti
individualHooks
?:
boolean
;
individualHooks
?:
boolean
;
/**
/**
* Ignore duplicate values for primary keys?
(not supported by postgres)
* Ignore duplicate values for primary keys?
*
*
* @default false
* @default false
*/
*/
...
@@ -1967,16 +1972,14 @@ export abstract class Model<TModelAttributes extends {} = any, TCreationAttribut
...
@@ -1967,16 +1972,14 @@ export abstract class Model<TModelAttributes extends {} = any, TCreationAttribut
/**
/**
* Builds a new model instance and calls save on it.
* Builds a new model instance and calls save on it.
*/
*/
public
static
create
<
M
extends
Model
>
(
public
static
create
<
M
extends
Model
,
O
extends
CreateOptions
<
M
[
'_attributes'
]
>
=
CreateOptions
<
M
[
'_attributes'
]
>
>
(
this
:
ModelStatic
<
M
>
,
this
:
ModelStatic
<
M
>
,
values
?:
M
[
'_creationAttributes'
],
values
?:
M
[
'_creationAttributes'
],
options
?:
CreateOptions
<
M
[
'_attributes'
]
>
options
?:
O
):
Promise
<
M
>
;
):
Promise
<
O
extends
{
returning
:
false
}
|
{
ignoreDuplicates
:
true
}
?
void
:
M
>
;
public
static
create
<
M
extends
Model
>
(
this
:
ModelStatic
<
M
>
,
values
:
M
[
'_creationAttributes'
],
options
:
CreateOptions
<
M
[
'_attributes'
]
>
&
{
returning
:
false
}
):
Promise
<
void
>
;
/**
/**
* Find a row that matches the query, or build (but don't save) the row if none is found.
* Find a row that matches the query, or build (but don't save) the row if none is found.
...
...
types/test/create.ts
0 → 100644
View file @
b33d78e
import
{
expectTypeOf
}
from
'expect-type'
import
{
User
}
from
'./models/User'
;
async
()
=>
{
const
user
=
await
User
.
create
({
id
:
123
,
firstName
:
'<first-name>'
,
},
{
ignoreDuplicates
:
false
,
returning
:
true
,
});
expectTypeOf
(
user
).
toEqualTypeOf
<
User
>
()
const
voidUsers
=
await
Promise
.
all
([
User
.
create
({
id
:
123
,
firstName
:
'<first-name>'
,
},
{
ignoreDuplicates
:
true
,
returning
:
false
,
}),
User
.
create
({
id
:
123
,
firstName
:
'<first-name>'
,
},
{
ignoreDuplicates
:
true
,
returning
:
true
,
}),
User
.
create
({
id
:
123
,
firstName
:
'<first-name>'
,
},
{
ignoreDuplicates
:
false
,
returning
:
false
,
}),
User
.
create
({
id
:
123
,
firstName
:
'<first-name>'
,
},
{
returning
:
false
}),
User
.
create
({
id
:
123
,
firstName
:
'<first-name>'
,
},
{
ignoreDuplicates
:
true
}),
]);
expectTypeOf
(
voidUsers
).
toEqualTypeOf
<
[
void
,
void
,
void
,
void
,
void
]
>
()
const
emptyUsers
=
await
Promise
.
all
([
User
.
create
(),
User
.
create
(
undefined
),
User
.
create
(
undefined
,
undefined
),
]);
expectTypeOf
(
emptyUsers
).
toEqualTypeOf
<
[
User
,
User
,
User
]
>
()
const
partialUser
=
await
User
.
create
({
id
:
123
,
firstName
:
'<first-name>'
,
lastName
:
'<last-name>'
,
},
{
fields
:
[
'firstName'
],
returning
:
[
'id'
],
});
expectTypeOf
(
partialUser
).
toEqualTypeOf
<
User
>
()
// @ts-expect-error missing attribute
await
User
.
create
({
id
:
123
,
});
await
User
.
create
({
id
:
123
,
firstName
:
'<first-name>'
,
// @ts-expect-error unknown attribute
unknown
:
'<unknown>'
,
});
};
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