Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/mayask/go-sqlc-scope.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148// Code generated by sqlc. DO NOT EDIT.// versions:// sqlc v1.30.0// source: users.sql
package db
import ( "context"
"github.com/jackc/pgx/v5/pgtype")
const createUser = `-- name: CreateUser :oneINSERT INTO users (tenant_id, business_id, name, role)VALUES ($1, $2, $3, $4)RETURNING id, tenant_id, business_id, name, role, created_at`
type CreateUserParams struct { TenantID pgtype.UUID BusinessID pgtype.UUID Name string Role string}
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) { row := q.db.QueryRow(ctx, createUser, arg.TenantID, arg.BusinessID, arg.Name, arg.Role, ) var i User err := row.Scan( &i.ID, &i.TenantID, &i.BusinessID, &i.Name, &i.Role, &i.CreatedAt, ) return i, err}
const getUserByID = `-- name: GetUserByID :oneSELECT id, tenant_id, business_id, name, role, created_at FROM usersWHERE require_scope($1, $2) AND (business_id = $1 OR $1 IS NULL) AND (tenant_id = $2 OR $2 IS NULL) AND id = $3`
type GetUserByIDParams struct { ScopeBusinessID pgtype.UUID ScopeTenantID pgtype.UUID ID pgtype.UUID}
func (q *Queries) GetUserByID(ctx context.Context, arg GetUserByIDParams) (User, error) { row := q.db.QueryRow(ctx, getUserByID, arg.ScopeBusinessID, arg.ScopeTenantID, arg.ID) var i User err := row.Scan( &i.ID, &i.TenantID, &i.BusinessID, &i.Name, &i.Role, &i.CreatedAt, ) return i, err}
const listAllUsers = `-- name: ListAllUsers :manySELECT id, tenant_id, business_id, name, role, created_at FROM usersORDER BY created_at`
// @sqlc-vet-disable require-scopefunc (q *Queries) ListAllUsers(ctx context.Context) ([]User, error) { rows, err := q.db.Query(ctx, listAllUsers) if err != nil { return nil, err } defer rows.Close() var items []User for rows.Next() { var i User if err := rows.Scan( &i.ID, &i.TenantID, &i.BusinessID, &i.Name, &i.Role, &i.CreatedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil}
const listUsers = `-- name: ListUsers :manySELECT id, tenant_id, business_id, name, role, created_at FROM usersWHERE require_scope($1, $2) AND (business_id = $1 OR $1 IS NULL) AND (tenant_id = $2 OR $2 IS NULL) AND (role = $3 OR $3 IS NULL)ORDER BY created_at`
type ListUsersParams struct { ScopeBusinessID pgtype.UUID ScopeTenantID pgtype.UUID Role *string}
func (q *Queries) ListUsers(ctx context.Context, arg ListUsersParams) ([]User, error) { rows, err := q.db.Query(ctx, listUsers, arg.ScopeBusinessID, arg.ScopeTenantID, arg.Role) if err != nil { return nil, err } defer rows.Close() var items []User for rows.Next() { var i User if err := rows.Scan( &i.ID, &i.TenantID, &i.BusinessID, &i.Name, &i.Role, &i.CreatedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil}