mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
fix: create storage without some attributes (#2358)
This commit is contained in:
@@ -8,8 +8,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (d *DB) CreateStorage(ctx context.Context, create *store.Storage) (*store.Storage, error) {
|
func (d *DB) CreateStorage(ctx context.Context, create *store.Storage) (*store.Storage, error) {
|
||||||
stmt := "INSERT INTO `storage` (`name`, `type`, `config`) VALUES (?, ?, ?)"
|
fields := []string{"`name`", "`type`", "`config`"}
|
||||||
result, err := d.db.ExecContext(ctx, stmt, create.Name, create.Type, create.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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@@ -8,16 +8,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (d *DB) CreateStorage(ctx context.Context, create *store.Storage) (*store.Storage, error) {
|
func (d *DB) CreateStorage(ctx context.Context, create *store.Storage) (*store.Storage, error) {
|
||||||
stmt := `
|
fields := []string{"`name`", "`type`", "`config`"}
|
||||||
INSERT INTO storage (
|
placeholder := []string{"?", "?", "?"}
|
||||||
name,
|
args := []any{create.Name, create.Type, create.Config}
|
||||||
type,
|
|
||||||
config
|
if create.ID != 0 {
|
||||||
)
|
fields = append(fields, "`id`")
|
||||||
VALUES (?, ?, ?)
|
placeholder = append(placeholder, "?")
|
||||||
RETURNING id
|
args = append(args, create.ID)
|
||||||
`
|
}
|
||||||
if err := d.db.QueryRowContext(ctx, stmt, create.Name, create.Type, create.Config).Scan(
|
|
||||||
|
stmt := "INSERT INTO `storage` (" + strings.Join(fields, ", ") + ") VALUES (" + strings.Join(placeholder, ", ") + ") RETURNING `id`"
|
||||||
|
if err := d.db.QueryRowContext(ctx, stmt, args...).Scan(
|
||||||
&create.ID,
|
&create.ID,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Reference in New Issue
Block a user