Initial open source release
This commit is contained in:
commit
74992e893f
377 changed files with 118084 additions and 0 deletions
124
internal/store/postgres/sqlcgen/authorization.sql.go
Normal file
124
internal/store/postgres/sqlcgen/authorization.sql.go
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: authorization.sql
|
||||
|
||||
package sqlcgen
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const deleteAuthorization = `-- name: DeleteAuthorization :exec
|
||||
DELETE FROM authorizations WHERE auth_key_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteAuthorization(ctx context.Context, authKeyID int64) error {
|
||||
_, err := q.db.Exec(ctx, deleteAuthorization, authKeyID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getAuthorizationByAuthKey = `-- name: GetAuthorizationByAuthKey :one
|
||||
SELECT auth_key_id, user_id, hash, layer, device_model, platform, system_version, api_id, app_version, ip, created_at, active_at FROM authorizations WHERE auth_key_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetAuthorizationByAuthKey(ctx context.Context, authKeyID int64) (Authorization, error) {
|
||||
row := q.db.QueryRow(ctx, getAuthorizationByAuthKey, authKeyID)
|
||||
var i Authorization
|
||||
err := row.Scan(
|
||||
&i.AuthKeyID,
|
||||
&i.UserID,
|
||||
&i.Hash,
|
||||
&i.Layer,
|
||||
&i.DeviceModel,
|
||||
&i.Platform,
|
||||
&i.SystemVersion,
|
||||
&i.ApiID,
|
||||
&i.AppVersion,
|
||||
&i.Ip,
|
||||
&i.CreatedAt,
|
||||
&i.ActiveAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listAuthorizationsByUser = `-- name: ListAuthorizationsByUser :many
|
||||
SELECT auth_key_id, user_id, hash, layer, device_model, platform, system_version, api_id, app_version, ip, created_at, active_at FROM authorizations
|
||||
WHERE user_id = $1
|
||||
ORDER BY active_at DESC, auth_key_id DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListAuthorizationsByUser(ctx context.Context, userID int64) ([]Authorization, error) {
|
||||
rows, err := q.db.Query(ctx, listAuthorizationsByUser, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Authorization
|
||||
for rows.Next() {
|
||||
var i Authorization
|
||||
if err := rows.Scan(
|
||||
&i.AuthKeyID,
|
||||
&i.UserID,
|
||||
&i.Hash,
|
||||
&i.Layer,
|
||||
&i.DeviceModel,
|
||||
&i.Platform,
|
||||
&i.SystemVersion,
|
||||
&i.ApiID,
|
||||
&i.AppVersion,
|
||||
&i.Ip,
|
||||
&i.CreatedAt,
|
||||
&i.ActiveAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const upsertAuthorization = `-- name: UpsertAuthorization :exec
|
||||
INSERT INTO authorizations (auth_key_id, user_id, layer, device_model, platform, system_version, api_id, app_version, ip)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
||||
ON CONFLICT (auth_key_id) DO UPDATE SET
|
||||
user_id = EXCLUDED.user_id,
|
||||
layer = EXCLUDED.layer,
|
||||
device_model = EXCLUDED.device_model,
|
||||
platform = EXCLUDED.platform,
|
||||
system_version = EXCLUDED.system_version,
|
||||
api_id = EXCLUDED.api_id,
|
||||
app_version = EXCLUDED.app_version,
|
||||
ip = EXCLUDED.ip,
|
||||
active_at = now()
|
||||
`
|
||||
|
||||
type UpsertAuthorizationParams struct {
|
||||
AuthKeyID int64
|
||||
UserID int64
|
||||
Layer int32
|
||||
DeviceModel string
|
||||
Platform string
|
||||
SystemVersion string
|
||||
ApiID int32
|
||||
AppVersion string
|
||||
Ip string
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertAuthorization(ctx context.Context, arg UpsertAuthorizationParams) error {
|
||||
_, err := q.db.Exec(ctx, upsertAuthorization,
|
||||
arg.AuthKeyID,
|
||||
arg.UserID,
|
||||
arg.Layer,
|
||||
arg.DeviceModel,
|
||||
arg.Platform,
|
||||
arg.SystemVersion,
|
||||
arg.ApiID,
|
||||
arg.AppVersion,
|
||||
arg.Ip,
|
||||
)
|
||||
return err
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue