mirror of
https://github.com/usememos/memos.git
synced 2024-11-11 01:12:40 +08:00
fix: CreateIdentityProvider without id (#2352)
This commit is contained in:
parent
b2aa66b4fd
commit
c0619ef4a4
2 changed files with 20 additions and 29 deletions
|
@ -22,15 +22,16 @@ func (d *DB) CreateIdentityProvider(ctx context.Context, create *store.IdentityP
|
|||
return nil, errors.Errorf("unsupported idp type %s", string(create.Type))
|
||||
}
|
||||
|
||||
stmt := "INSERT INTO `idp` (`name`, `type`, `identifier_filter`, `config`) VALUES (?, ?, ?, ?)"
|
||||
result, err := d.db.ExecContext(
|
||||
ctx,
|
||||
stmt,
|
||||
create.Name,
|
||||
create.Type,
|
||||
create.IdentifierFilter,
|
||||
string(configBytes),
|
||||
)
|
||||
placeholders := []string{"?", "?", "?", "?"}
|
||||
fields := []string{"`name`", "`type`", "`identifier_filter`", "`config`"}
|
||||
args := []any{create.Name, create.Type, create.IdentifierFilter, string(configBytes)}
|
||||
|
||||
if create.ID != 0 {
|
||||
fields, placeholders, args = append(fields, "`id`"), append(placeholders, "?"), append(args, create.ID)
|
||||
}
|
||||
|
||||
stmt := "INSERT INTO `idp` (" + strings.Join(fields, ", ") + ") VALUES (" + strings.Join(placeholders, ", ") + ")"
|
||||
result, err := d.db.ExecContext(ctx, stmt, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -23,26 +23,16 @@ func (d *DB) CreateIdentityProvider(ctx context.Context, create *store.IdentityP
|
|||
return nil, errors.Errorf("unsupported idp type %s", string(create.Type))
|
||||
}
|
||||
|
||||
stmt := `
|
||||
INSERT INTO idp (
|
||||
name,
|
||||
type,
|
||||
identifier_filter,
|
||||
config
|
||||
)
|
||||
VALUES (?, ?, ?, ?)
|
||||
RETURNING id
|
||||
`
|
||||
if err := d.db.QueryRowContext(
|
||||
ctx,
|
||||
stmt,
|
||||
create.Name,
|
||||
create.Type,
|
||||
create.IdentifierFilter,
|
||||
string(configBytes),
|
||||
).Scan(
|
||||
&create.ID,
|
||||
); err != nil {
|
||||
placeholders := []string{"?", "?", "?", "?"}
|
||||
fields := []string{"`name`", "`type`", "`identifier_filter`", "`config`"}
|
||||
args := []any{create.Name, create.Type, create.IdentifierFilter, string(configBytes)}
|
||||
|
||||
if create.ID != 0 {
|
||||
fields, placeholders, args = append(fields, "`id`"), append(placeholders, "?"), append(args, create.ID)
|
||||
}
|
||||
|
||||
stmt := "INSERT INTO `idp` (" + strings.Join(fields, ", ") + ") VALUES (" + strings.Join(placeholders, ", ") + ") RETURNING `id`"
|
||||
if err := d.db.QueryRowContext(ctx, stmt, args...).Scan(&create.ID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue