u
This commit is contained in:
1 parent
1903861354
commit
1b1a54f7dd
35 files changed
+1185
-535
No files matched your search
@@ -9,8 +9,18 @@ import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const deleteSpace = `-- name: DeleteSpace :exec
|
||||
DELETE FROM space WHERE id = $1
|
||||
`
|
||||
|
||||
// 删除空间
|
||||
func (q *Queries) DeleteSpace(ctx context.Context, id int64) error {
|
||||
_, err := q.db.Exec(ctx, deleteSpace, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const getSpaceById = `-- name: GetSpaceById :one
|
||||
SELECT id, name, invite_code, owner_id, create_time, update_time FROM space WHERE id = $1
|
||||
SELECT id, name, invite_code, create_time, update_time FROM space WHERE id = $1
|
||||
`
|
||||
|
||||
// 根据id获取分享空间信息
|
||||
@@ -21,9 +31,44 @@ func (q *Queries) GetSpaceById(ctx context.Context, id int64) (Space, error) {
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.InviteCode,
|
||||
&i.OwnerID,
|
||||
&i.CreateTime,
|
||||
&i.UpdateTime,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getSpaceByInviteCode = `-- name: GetSpaceByInviteCode :one
|
||||
SELECT id, name, invite_code, create_time, update_time FROM space WHERE invite_code = $1
|
||||
`
|
||||
|
||||
// 根据邀请码获取
|
||||
func (q *Queries) GetSpaceByInviteCode(ctx context.Context, inviteCode string) (Space, error) {
|
||||
row := q.db.QueryRow(ctx, getSpaceByInviteCode, inviteCode)
|
||||
var i Space
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.InviteCode,
|
||||
&i.CreateTime,
|
||||
&i.UpdateTime,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertSpace = `-- name: InsertSpace :exec
|
||||
INSERT INTO space (
|
||||
id,name,invite_code,create_time,update_time
|
||||
) VALUES ($1,$2,$3,NOW(),NOW())
|
||||
`
|
||||
|
||||
type InsertSpaceParams struct {
|
||||
ID int64
|
||||
Name string
|
||||
InviteCode string
|
||||
}
|
||||
|
||||
// 创建空间
|
||||
func (q *Queries) InsertSpace(ctx context.Context, arg InsertSpaceParams) error {
|
||||
_, err := q.db.Exec(ctx, insertSpace, arg.ID, arg.Name, arg.InviteCode)
|
||||
return err
|
||||
}
|
||||
Reference in new issue
Block a user