Loggest thy stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

259 lines
6.1 KiB

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.13.0
// source: scope.sql
package mysqlcore
import (
"context"
"database/sql"
)
const deleteAllScopeMembers = `-- name: DeleteAllScopeMembers :exec
DELETE FROM scope_member WHERE scope_id=?
`
func (q *Queries) DeleteAllScopeMembers(ctx context.Context, scopeID int) error {
_, err := q.exec(ctx, q.deleteAllScopeMembersStmt, deleteAllScopeMembers, scopeID)
return err
}
const deleteScope = `-- name: DeleteScope :exec
DELETE FROM scope WHERE id=?
`
func (q *Queries) DeleteScope(ctx context.Context, id int) error {
_, err := q.exec(ctx, q.deleteScopeStmt, deleteScope, id)
return err
}
const deleteScopeMember = `-- name: DeleteScopeMember :exec
DELETE FROM scope_member WHERE scope_id=? AND user_id=?
`
type DeleteScopeMemberParams struct {
ScopeID int
UserID string
}
func (q *Queries) DeleteScopeMember(ctx context.Context, arg DeleteScopeMemberParams) error {
_, err := q.exec(ctx, q.deleteScopeMemberStmt, deleteScopeMember, arg.ScopeID, arg.UserID)
return err
}
const getScope = `-- name: GetScope :one
SELECT id, name, abbreviation FROM scope
WHERE id = ?
`
func (q *Queries) GetScope(ctx context.Context, id int) (Scope, error) {
row := q.queryRow(ctx, q.getScopeStmt, getScope, id)
var i Scope
err := row.Scan(&i.ID, &i.Name, &i.Abbreviation)
return i, err
}
const getScopeDisplayName = `-- name: GetScopeDisplayName :one
SELECT name FROM scope_member
WHERE user_id = ? AND scope_id = ?
`
type GetScopeDisplayNameParams struct {
UserID string
ScopeID int
}
func (q *Queries) GetScopeDisplayName(ctx context.Context, arg GetScopeDisplayNameParams) (string, error) {
row := q.queryRow(ctx, q.getScopeDisplayNameStmt, getScopeDisplayName, arg.UserID, arg.ScopeID)
var name string
err := row.Scan(&name)
return name, err
}
const getScopeWithDisplayName = `-- name: GetScopeWithDisplayName :one
SELECT id, scope.name, abbreviation, sm.name AS display_name FROM scope
LEFT JOIN scope_member sm ON scope.id = sm.scope_id
WHERE id = ? AND sm.user_id = ?
`
type GetScopeWithDisplayNameParams struct {
ID int
UserID string
}
type GetScopeWithDisplayNameRow struct {
ID int
Name string
Abbreviation string
DisplayName sql.NullString
}
func (q *Queries) GetScopeWithDisplayName(ctx context.Context, arg GetScopeWithDisplayNameParams) (GetScopeWithDisplayNameRow, error) {
row := q.queryRow(ctx, q.getScopeWithDisplayNameStmt, getScopeWithDisplayName, arg.ID, arg.UserID)
var i GetScopeWithDisplayNameRow
err := row.Scan(
&i.ID,
&i.Name,
&i.Abbreviation,
&i.DisplayName,
)
return i, err
}
const insertScope = `-- name: InsertScope :execresult
INSERT INTO scope (id, name, abbreviation)
VALUES (?, ?, ?)
`
type InsertScopeParams struct {
ID int
Name string
Abbreviation string
}
func (q *Queries) InsertScope(ctx context.Context, arg InsertScopeParams) (sql.Result, error) {
return q.exec(ctx, q.insertScopeStmt, insertScope, arg.ID, arg.Name, arg.Abbreviation)
}
const listScopeMembers = `-- name: ListScopeMembers :many
SELECT user_id, name, owner FROM scope_member
WHERE scope_id = ?
ORDER BY name
`
type ListScopeMembersRow struct {
UserID string
Name string
Owner bool
}
func (q *Queries) ListScopeMembers(ctx context.Context, scopeID int) ([]ListScopeMembersRow, error) {
rows, err := q.query(ctx, q.listScopeMembersStmt, listScopeMembers, scopeID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListScopeMembersRow{}
for rows.Next() {
var i ListScopeMembersRow
if err := rows.Scan(&i.UserID, &i.Name, &i.Owner); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listScopes = `-- name: ListScopes :many
SELECT id, name, abbreviation FROM scope
ORDER BY name
`
func (q *Queries) ListScopes(ctx context.Context) ([]Scope, error) {
rows, err := q.query(ctx, q.listScopesStmt, listScopes)
if err != nil {
return nil, err
}
defer rows.Close()
items := []Scope{}
for rows.Next() {
var i Scope
if err := rows.Scan(&i.ID, &i.Name, &i.Abbreviation); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listScopesByUser = `-- name: ListScopesByUser :many
SELECT id, s.name, abbreviation, sm.name as display_name FROM scope_member sm
RIGHT JOIN scope s on s.id = sm.scope_id
WHERE sm.user_id = ?
ORDER BY s.name
`
type ListScopesByUserRow struct {
ID int
Name string
Abbreviation string
DisplayName sql.NullString
}
func (q *Queries) ListScopesByUser(ctx context.Context, userID string) ([]ListScopesByUserRow, error) {
rows, err := q.query(ctx, q.listScopesByUserStmt, listScopesByUser, userID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListScopesByUserRow{}
for rows.Next() {
var i ListScopesByUserRow
if err := rows.Scan(
&i.ID,
&i.Name,
&i.Abbreviation,
&i.DisplayName,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const updateScope = `-- name: UpdateScope :exec
UPDATE scope SET name = ?, abbreviation = ? WHERE id = ?
`
type UpdateScopeParams struct {
Name string
Abbreviation string
ID int
}
func (q *Queries) UpdateScope(ctx context.Context, arg UpdateScopeParams) error {
_, err := q.exec(ctx, q.updateScopeStmt, updateScope, arg.Name, arg.Abbreviation, arg.ID)
return err
}
const updateScopeMember = `-- name: UpdateScopeMember :exec
REPLACE INTO scope_member (scope_id, user_id, name, owner)
VALUES (?, ?, ?, ?)
`
type UpdateScopeMemberParams struct {
ScopeID int
UserID string
Name string
Owner bool
}
func (q *Queries) UpdateScopeMember(ctx context.Context, arg UpdateScopeMemberParams) error {
_, err := q.exec(ctx, q.updateScopeMemberStmt, updateScopeMember,
arg.ScopeID,
arg.UserID,
arg.Name,
arg.Owner,
)
return err
}