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 cd8ee566
authored
Jun 17, 2019
by
Levi Bostian
Committed by
Simon Schick
Jun 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(types): add missing findCreateFind type (#11068)
1 parent
dcf079b2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
1 deletions
types/lib/model.d.ts
types/test/model.ts
types/lib/model.d.ts
View file @
cd8ee56
...
...
@@ -1925,6 +1925,15 @@ export abstract class Model<T = any, T2 = any> extends Hooks {
):
Promise
<
[
M
,
boolean
]
>
;
/**
* A more performant findOrCreate that will not work under a transaction (at least not in postgres)
* Will execute a find call, if empty then attempt to create, if unique constraint then attempt to find again
*/
public
static
findCreateFind
<
M
extends
Model
>
(
this
:
{
new
():
M
}
&
typeof
Model
,
options
:
FindOrCreateOptions
):
Promise
<
[
M
,
boolean
]
>
;
/**
* Insert or update a single row. An update will be executed if a row which matches the supplied values on
* either the primary key or a unique key is found. Note that the unique index must be defined in your
* sequelize model and not just in the table. Otherwise you may experience a unique constraint violation,
...
...
types/test/model.ts
View file @
cd8ee56
import
{
Association
,
HasOne
,
Model
,
Sequelize
}
from
'sequelize'
;
import
{
Association
,
HasOne
,
Model
,
Sequelize
,
DataTypes
}
from
'sequelize'
;
class
MyModel
extends
Model
{
public
num
!
:
number
;
...
...
@@ -36,3 +36,25 @@ MyModel.init({}, {
sequelize
,
tableName
:
'my_model'
});
/**
* Tests for findCreateFind() type.
*/
class
UserModel
extends
Model
{}
UserModel
.
init
({
username
:
{
type
:
DataTypes
.
STRING
,
allowNull
:
false
},
beta_user
:
{
type
:
DataTypes
.
BOOLEAN
,
allowNull
:
false
}
},
{
sequelize
:
sequelize
})
UserModel
.
findCreateFind
({
where
:
{
username
:
"new user username"
},
defaults
:
{
beta_user
:
true
}
})
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