u
This commit is contained in:
1 parent
4ce951dd56
commit
8a3dea8545
44 files changed
+1599
-30
No files matched your search
@@ -0,0 +1,32 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
|
||||
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
|
||||
QueryRow(context.Context, string, ...interface{}) pgx.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package repo
|
||||
|
||||
import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type Space struct {
|
||||
ID int64
|
||||
Name string
|
||||
InviteCode string
|
||||
OwnerID int64
|
||||
CreateTime pgtype.Timestamptz
|
||||
UpdateTime pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type SpaceMember struct {
|
||||
ID int64
|
||||
SpaceID int64
|
||||
UserID int64
|
||||
Role int16
|
||||
JoinTime pgtype.Timestamptz
|
||||
UpdateTime pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID int64
|
||||
Nickname string
|
||||
Avatar string
|
||||
Status int32
|
||||
LastLoginTime pgtype.Timestamptz
|
||||
CreateTime pgtype.Timestamptz
|
||||
UpdateTime pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type UserOauth struct {
|
||||
ID int64
|
||||
UserID int64
|
||||
Type int32
|
||||
Openid string
|
||||
CreateTime pgtype.Timestamptz
|
||||
UpdateTime pgtype.Timestamptz
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: space.sql
|
||||
|
||||
package repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const getSpaceById = `-- name: GetSpaceById :one
|
||||
SELECT id, name, invite_code, owner_id, create_time, update_time FROM space WHERE id = $1
|
||||
`
|
||||
|
||||
// 根据id获取分享空间信息
|
||||
func (q *Queries) GetSpaceById(ctx context.Context, id int64) (Space, error) {
|
||||
row := q.db.QueryRow(ctx, getSpaceById, id)
|
||||
var i Space
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.InviteCode,
|
||||
&i.OwnerID,
|
||||
&i.CreateTime,
|
||||
&i.UpdateTime,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: space_member.sql
|
||||
|
||||
package repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const getUserSpaceRole = `-- name: GetUserSpaceRole :one
|
||||
SELECT role
|
||||
FROM space_member
|
||||
WHERE user_id = $1
|
||||
AND space_id = $2
|
||||
`
|
||||
|
||||
type GetUserSpaceRoleParams struct {
|
||||
UserID int64
|
||||
SpaceID int64
|
||||
}
|
||||
|
||||
// 获取用户在指定空间的角色
|
||||
func (q *Queries) GetUserSpaceRole(ctx context.Context, arg GetUserSpaceRoleParams) (int16, error) {
|
||||
row := q.db.QueryRow(ctx, getUserSpaceRole, arg.UserID, arg.SpaceID)
|
||||
var role int16
|
||||
err := row.Scan(&role)
|
||||
return role, err
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: user.sql
|
||||
|
||||
package repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const findUserByOpenID = `-- name: FindUserByOpenID :one
|
||||
SELECT
|
||||
u.id AS user_id,
|
||||
u.nickname,
|
||||
u.avatar,
|
||||
u.status,
|
||||
o.type AS login_type,
|
||||
o.openid
|
||||
FROM user_oauth o
|
||||
JOIN "user" u ON u.id = o.user_id
|
||||
WHERE o.openid = $1
|
||||
AND o.type = $2
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
type FindUserByOpenIDParams struct {
|
||||
Openid string
|
||||
Type int32
|
||||
}
|
||||
|
||||
type FindUserByOpenIDRow struct {
|
||||
UserID int64
|
||||
Nickname string
|
||||
Avatar string
|
||||
Status int32
|
||||
LoginType int32
|
||||
Openid string
|
||||
}
|
||||
|
||||
func (q *Queries) FindUserByOpenID(ctx context.Context, arg FindUserByOpenIDParams) (FindUserByOpenIDRow, error) {
|
||||
row := q.db.QueryRow(ctx, findUserByOpenID, arg.Openid, arg.Type)
|
||||
var i FindUserByOpenIDRow
|
||||
err := row.Scan(
|
||||
&i.UserID,
|
||||
&i.Nickname,
|
||||
&i.Avatar,
|
||||
&i.Status,
|
||||
&i.LoginType,
|
||||
&i.Openid,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertUser = `-- name: InsertUser :exec
|
||||
INSERT INTO "user" (
|
||||
id,
|
||||
nickname,
|
||||
avatar,
|
||||
status,
|
||||
create_time,
|
||||
update_time,
|
||||
last_login_time
|
||||
) VALUES (
|
||||
$1, $2, $3,$4, NOW(), NOW(),now()
|
||||
)
|
||||
`
|
||||
|
||||
type InsertUserParams struct {
|
||||
ID int64
|
||||
Nickname string
|
||||
Avatar string
|
||||
Status int32
|
||||
}
|
||||
|
||||
func (q *Queries) InsertUser(ctx context.Context, arg InsertUserParams) error {
|
||||
_, err := q.db.Exec(ctx, insertUser,
|
||||
arg.ID,
|
||||
arg.Nickname,
|
||||
arg.Avatar,
|
||||
arg.Status,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateUserLastLoginTime = `-- name: UpdateUserLastLoginTime :exec
|
||||
UPDATE "user"
|
||||
SET last_login_time = NOW()
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) UpdateUserLastLoginTime(ctx context.Context, id int64) error {
|
||||
_, err := q.db.Exec(ctx, updateUserLastLoginTime, id)
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: user_oauth.sql
|
||||
|
||||
package repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const insertUserOAuth = `-- name: InsertUserOAuth :exec
|
||||
INSERT INTO user_oauth (
|
||||
id,
|
||||
user_id,
|
||||
type,
|
||||
openid,
|
||||
create_time,
|
||||
update_time
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, NOW(), NOW()
|
||||
)
|
||||
`
|
||||
|
||||
type InsertUserOAuthParams struct {
|
||||
ID int64
|
||||
UserID int64
|
||||
Type int32
|
||||
Openid string
|
||||
}
|
||||
|
||||
func (q *Queries) InsertUserOAuth(ctx context.Context, arg InsertUserOAuthParams) error {
|
||||
_, err := q.db.Exec(ctx, insertUserOAuth,
|
||||
arg.ID,
|
||||
arg.UserID,
|
||||
arg.Type,
|
||||
arg.Openid,
|
||||
)
|
||||
return err
|
||||
}
|
||||
Reference in new issue
Block a user