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
55e0fbf2
Unverified
Commit
55e0fbf2
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 activity without some attributes (#2356)
parent
eaac17a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
18 deletions
+38
-18
activity.go
store/db/mysql/activity.go
+19
-7
activity.go
store/db/sqlite/activity.go
+19
-11
No files found.
store/db/mysql/activity.go
View file @
55e0fbf2
...
...
@@ -2,6 +2,7 @@ package mysql
import
(
"context"
"strings"
"github.com/pkg/errors"
...
...
@@ -9,13 +10,24 @@ import (
)
func
(
d
*
DB
)
CreateActivity
(
ctx
context
.
Context
,
create
*
store
.
Activity
)
(
*
store
.
Activity
,
error
)
{
stmt
:=
"INSERT INTO activity (`creator_id`, `type`, `level`, `payload`) VALUES (?, ?, ?, ?)"
result
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
create
.
CreatorID
,
create
.
Type
,
create
.
Level
,
create
.
Payload
,
)
fields
:=
[]
string
{
"`creator_id`"
,
"`type`"
,
"`level`"
,
"`payload`"
}
placeholder
:=
[]
string
{
"?"
,
"?"
,
"?"
,
"?"
}
args
:=
[]
any
{
create
.
CreatorID
,
create
.
Type
,
create
.
Level
,
create
.
Payload
}
if
create
.
ID
!=
0
{
fields
=
append
(
fields
,
"`id`"
)
placeholder
=
append
(
placeholder
,
"?"
)
args
=
append
(
args
,
create
.
ID
)
}
if
create
.
CreatedTs
!=
0
{
fields
=
append
(
fields
,
"`created_ts`"
)
placeholder
=
append
(
placeholder
,
"FROM_UNIXTIME(?)"
)
args
=
append
(
args
,
create
.
CreatedTs
)
}
stmt
:=
"INSERT INTO activity ("
+
strings
.
Join
(
fields
,
", "
)
+
") VALUES ("
+
strings
.
Join
(
placeholder
,
", "
)
+
")"
result
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
args
...
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"failed to execute statement"
)
}
...
...
store/db/sqlite/activity.go
View file @
55e0fbf2
...
...
@@ -2,22 +2,30 @@ package sqlite
import
(
"context"
"strings"
"github.com/usememos/memos/store"
)
func
(
d
*
DB
)
CreateActivity
(
ctx
context
.
Context
,
create
*
store
.
Activity
)
(
*
store
.
Activity
,
error
)
{
stmt
:=
`
INSERT INTO activity (
creator_id,
type,
level,
payload
)
VALUES (?, ?, ?, ?)
RETURNING id, created_ts
`
if
err
:=
d
.
db
.
QueryRowContext
(
ctx
,
stmt
,
create
.
CreatorID
,
create
.
Type
,
create
.
Level
,
create
.
Payload
)
.
Scan
(
fields
:=
[]
string
{
"`creator_id`"
,
"`type`"
,
"`level`"
,
"`payload`"
}
placeholder
:=
[]
string
{
"?"
,
"?"
,
"?"
,
"?"
}
args
:=
[]
any
{
create
.
CreatorID
,
create
.
Type
,
create
.
Level
,
create
.
Payload
}
if
create
.
ID
!=
0
{
fields
=
append
(
fields
,
"`id`"
)
placeholder
=
append
(
placeholder
,
"?"
)
args
=
append
(
args
,
create
.
ID
)
}
if
create
.
CreatedTs
!=
0
{
fields
=
append
(
fields
,
"`created_ts`"
)
placeholder
=
append
(
placeholder
,
"?"
)
args
=
append
(
args
,
create
.
CreatedTs
)
}
stmt
:=
"INSERT INTO activity ("
+
strings
.
Join
(
fields
,
", "
)
+
") VALUES ("
+
strings
.
Join
(
placeholder
,
", "
)
+
") RETURNING `id`, `created_ts`"
if
err
:=
d
.
db
.
QueryRowContext
(
ctx
,
stmt
,
args
...
)
.
Scan
(
&
create
.
ID
,
&
create
.
CreatedTs
,
);
err
!=
nil
{
...
...
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