mirror of
https://github.com/usememos/memos.git
synced 2024-11-11 01:12:40 +08:00
fix: create storage without some attributes (#2358)
This commit is contained in:
parent
7680be1a2f
commit
287f1beb90
2 changed files with 24 additions and 12 deletions
|
@ -8,8 +8,18 @@ import (
|
|||
)
|
||||
|
||||
func (d *DB) CreateStorage(ctx context.Context, create *store.Storage) (*store.Storage, error) {
|
||||
stmt := "INSERT INTO `storage` (`name`, `type`, `config`) VALUES (?, ?, ?)"
|
||||
result, err := d.db.ExecContext(ctx, stmt, create.Name, create.Type, create.Config)
|
||||
fields := []string{"`name`", "`type`", "`config`"}
|
||||
placeholder := []string{"?", "?", "?"}
|
||||
args := []any{create.Name, create.Type, create.Config}
|
||||
|
||||
if create.ID != 0 {
|
||||
fields = append(fields, "`id`")
|
||||
placeholder = append(placeholder, "?")
|
||||
args = append(args, create.ID)
|
||||
}
|
||||
|
||||
stmt := "INSERT INTO `storage` (" + strings.Join(fields, ", ") + ") VALUES (" + strings.Join(placeholder, ", ") + ")"
|
||||
result, err := d.db.ExecContext(ctx, stmt, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -8,16 +8,18 @@ import (
|
|||
)
|
||||
|
||||
func (d *DB) CreateStorage(ctx context.Context, create *store.Storage) (*store.Storage, error) {
|
||||
stmt := `
|
||||
INSERT INTO storage (
|
||||
name,
|
||||
type,
|
||||
config
|
||||
)
|
||||
VALUES (?, ?, ?)
|
||||
RETURNING id
|
||||
`
|
||||
if err := d.db.QueryRowContext(ctx, stmt, create.Name, create.Type, create.Config).Scan(
|
||||
fields := []string{"`name`", "`type`", "`config`"}
|
||||
placeholder := []string{"?", "?", "?"}
|
||||
args := []any{create.Name, create.Type, create.Config}
|
||||
|
||||
if create.ID != 0 {
|
||||
fields = append(fields, "`id`")
|
||||
placeholder = append(placeholder, "?")
|
||||
args = append(args, create.ID)
|
||||
}
|
||||
|
||||
stmt := "INSERT INTO `storage` (" + strings.Join(fields, ", ") + ") VALUES (" + strings.Join(placeholder, ", ") + ") RETURNING `id`"
|
||||
if err := d.db.QueryRowContext(ctx, stmt, args...).Scan(
|
||||
&create.ID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
|
|
Loading…
Reference in a new issue