Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
287f1beb
Unverified
Commit
287f1beb
authored
Oct 08, 2023
by
Athurg Gooth
Committed by
GitHub
Oct 08, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: create storage without some attributes (#2358)
parent
7680be1a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
12 deletions
+24
-12
storage.go
store/db/mysql/storage.go
+12
-2
storage.go
store/db/sqlite/storage.go
+12
-10
No files found.
store/db/mysql/storage.go
View file @
287f1beb
...
@@ -8,8 +8,18 @@ import (
...
@@ -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
}
}
...
...
store/db/sqlite/storage.go
View file @
287f1beb
...
@@ -8,16 +8,18 @@ import (
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment