WIP: Migrate from GORM to sqlc - partial migration, build broken
This commit is contained in:
parent
560b40503a
commit
dad96978e0
20 changed files with 1241 additions and 709 deletions
141
backend/internal/db/sqlc/aliases.sql.go
Normal file
141
backend/internal/db/sqlc/aliases.sql.go
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: aliases.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const countAliasesByDomain = `-- name: CountAliasesByDomain :one
|
||||
SELECT COUNT(*) as count FROM virtual_aliases WHERE domain_id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) CountAliasesByDomain(ctx context.Context, domainID uint32) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, countAliasesByDomain, domainID)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const createAlias = `-- name: CreateAlias :exec
|
||||
INSERT INTO virtual_aliases (domain_id, source, destination) VALUES (?, ?, ?)
|
||||
`
|
||||
|
||||
type CreateAliasParams struct {
|
||||
DomainID uint32 `json:"domain_id"`
|
||||
Source string `json:"source"`
|
||||
Destination string `json:"destination"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateAlias(ctx context.Context, arg CreateAliasParams) error {
|
||||
_, err := q.db.ExecContext(ctx, createAlias, arg.DomainID, arg.Source, arg.Destination)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteAlias = `-- name: DeleteAlias :exec
|
||||
DELETE FROM virtual_aliases WHERE id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteAlias(ctx context.Context, id uint32) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteAlias, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const getAliasByID = `-- name: GetAliasByID :one
|
||||
SELECT id, domain_id, source, destination FROM virtual_aliases WHERE id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetAliasByID(ctx context.Context, id uint32) (VirtualAlias, error) {
|
||||
row := q.db.QueryRowContext(ctx, getAliasByID, id)
|
||||
var i VirtualAlias
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.DomainID,
|
||||
&i.Source,
|
||||
&i.Destination,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getAliasBySource = `-- name: GetAliasBySource :one
|
||||
SELECT id, domain_id, source, destination FROM virtual_aliases WHERE source = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetAliasBySource(ctx context.Context, source string) (VirtualAlias, error) {
|
||||
row := q.db.QueryRowContext(ctx, getAliasBySource, source)
|
||||
var i VirtualAlias
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.DomainID,
|
||||
&i.Source,
|
||||
&i.Destination,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getAliasesByDomain = `-- name: GetAliasesByDomain :many
|
||||
SELECT id, domain_id, source, destination FROM virtual_aliases WHERE domain_id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetAliasesByDomain(ctx context.Context, domainID uint32) ([]VirtualAlias, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getAliasesByDomain, domainID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []VirtualAlias
|
||||
for rows.Next() {
|
||||
var i VirtualAlias
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.DomainID,
|
||||
&i.Source,
|
||||
&i.Destination,
|
||||
); 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 getAllAliases = `-- name: GetAllAliases :many
|
||||
SELECT id, domain_id, source, destination FROM virtual_aliases
|
||||
`
|
||||
|
||||
func (q *Queries) GetAllAliases(ctx context.Context) ([]VirtualAlias, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getAllAliases)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []VirtualAlias
|
||||
for rows.Next() {
|
||||
var i VirtualAlias
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.DomainID,
|
||||
&i.Source,
|
||||
&i.Destination,
|
||||
); 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
|
||||
}
|
||||
31
backend/internal/db/sqlc/db.go
Normal file
31
backend/internal/db/sqlc/db.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
|
||||
PrepareContext(context.Context, string) (*sql.Stmt, error)
|
||||
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
|
||||
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
}
|
||||
}
|
||||
128
backend/internal/db/sqlc/domains.sql.go
Normal file
128
backend/internal/db/sqlc/domains.sql.go
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: domains.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
const createDomain = `-- name: CreateDomain :exec
|
||||
INSERT INTO virtual_domains (name) VALUES (?)
|
||||
`
|
||||
|
||||
func (q *Queries) CreateDomain(ctx context.Context, name string) error {
|
||||
_, err := q.db.ExecContext(ctx, createDomain, name)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteDomain = `-- name: DeleteDomain :exec
|
||||
DELETE FROM virtual_domains WHERE id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteDomain(ctx context.Context, id uint32) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteDomain, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const getAllDomains = `-- name: GetAllDomains :many
|
||||
SELECT id, name, created_at FROM virtual_domains ORDER BY name ASC
|
||||
`
|
||||
|
||||
func (q *Queries) GetAllDomains(ctx context.Context) ([]VirtualDomain, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getAllDomains)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []VirtualDomain
|
||||
for rows.Next() {
|
||||
var i VirtualDomain
|
||||
if err := rows.Scan(&i.ID, &i.Name, &i.CreatedAt); 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 getAllDomainsWithCounts = `-- name: GetAllDomainsWithCounts :many
|
||||
SELECT
|
||||
d.id,
|
||||
d.name,
|
||||
d.created_at,
|
||||
COALESCE(u.user_count, 0) as user_count,
|
||||
COALESCE(a.alias_count, 0) as alias_count
|
||||
FROM virtual_domains d
|
||||
LEFT JOIN (SELECT domain_id, COUNT(*) as user_count FROM virtual_users GROUP BY domain_id) u ON u.domain_id = d.id
|
||||
LEFT JOIN (SELECT domain_id, COUNT(*) as alias_count FROM virtual_aliases GROUP BY domain_id) a ON a.domain_id = d.id
|
||||
ORDER BY d.name ASC
|
||||
`
|
||||
|
||||
type GetAllDomainsWithCountsRow struct {
|
||||
ID uint32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
CreatedAt sql.NullTime `json:"created_at"`
|
||||
UserCount int64 `json:"user_count"`
|
||||
AliasCount int64 `json:"alias_count"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetAllDomainsWithCounts(ctx context.Context) ([]GetAllDomainsWithCountsRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getAllDomainsWithCounts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetAllDomainsWithCountsRow
|
||||
for rows.Next() {
|
||||
var i GetAllDomainsWithCountsRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.CreatedAt,
|
||||
&i.UserCount,
|
||||
&i.AliasCount,
|
||||
); 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 getDomainByID = `-- name: GetDomainByID :one
|
||||
SELECT id, name, created_at FROM virtual_domains WHERE id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetDomainByID(ctx context.Context, id uint32) (VirtualDomain, error) {
|
||||
row := q.db.QueryRowContext(ctx, getDomainByID, id)
|
||||
var i VirtualDomain
|
||||
err := row.Scan(&i.ID, &i.Name, &i.CreatedAt)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getDomainByName = `-- name: GetDomainByName :one
|
||||
SELECT id, name, created_at FROM virtual_domains WHERE name = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetDomainByName(ctx context.Context, name string) (VirtualDomain, error) {
|
||||
row := q.db.QueryRowContext(ctx, getDomainByName, name)
|
||||
var i VirtualDomain
|
||||
err := row.Scan(&i.ID, &i.Name, &i.CreatedAt)
|
||||
return i, err
|
||||
}
|
||||
233
backend/internal/db/sqlc/imc_users.sql.go
Normal file
233
backend/internal/db/sqlc/imc_users.sql.go
Normal file
|
|
@ -0,0 +1,233 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: imc_users.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const addUserToDomain = `-- name: AddUserToDomain :exec
|
||||
INSERT INTO imc_users2domains (user_id, domain_id) VALUES (?, ?)
|
||||
`
|
||||
|
||||
type AddUserToDomainParams struct {
|
||||
UserID uint32 `json:"user_id"`
|
||||
DomainID uint32 `json:"domain_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) AddUserToDomain(ctx context.Context, arg AddUserToDomainParams) error {
|
||||
_, err := q.db.ExecContext(ctx, addUserToDomain, arg.UserID, arg.DomainID)
|
||||
return err
|
||||
}
|
||||
|
||||
const createImcUser = `-- name: CreateImcUser :exec
|
||||
INSERT INTO imc_users (username, password_hash, role, domain_id) VALUES (?, ?, ?, ?)
|
||||
`
|
||||
|
||||
type CreateImcUserParams struct {
|
||||
Username string `json:"username"`
|
||||
PasswordHash string `json:"password_hash"`
|
||||
Role NullImcUsersRole `json:"role"`
|
||||
DomainID uint32 `json:"domain_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateImcUser(ctx context.Context, arg CreateImcUserParams) error {
|
||||
_, err := q.db.ExecContext(ctx, createImcUser,
|
||||
arg.Username,
|
||||
arg.PasswordHash,
|
||||
arg.Role,
|
||||
arg.DomainID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteImcUser = `-- name: DeleteImcUser :exec
|
||||
DELETE FROM imc_users WHERE id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteImcUser(ctx context.Context, id uint32) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteImcUser, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const getAdditionalDomainsForUser = `-- name: GetAdditionalDomainsForUser :many
|
||||
SELECT virtual_domains.id, virtual_domains.name, virtual_domains.created_at FROM virtual_domains
|
||||
JOIN imc_users2domains ON virtual_domains.id = imc_users2domains.domain_id
|
||||
WHERE imc_users2domains.user_id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetAdditionalDomainsForUser(ctx context.Context, userID uint32) ([]VirtualDomain, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getAdditionalDomainsForUser, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []VirtualDomain
|
||||
for rows.Next() {
|
||||
var i VirtualDomain
|
||||
if err := rows.Scan(&i.ID, &i.Name, &i.CreatedAt); 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 getImcUserByID = `-- name: GetImcUserByID :one
|
||||
SELECT id, username, password_hash, role, domain_id, created_at FROM imc_users WHERE id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetImcUserByID(ctx context.Context, id uint32) (ImcUser, error) {
|
||||
row := q.db.QueryRowContext(ctx, getImcUserByID, id)
|
||||
var i ImcUser
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Username,
|
||||
&i.PasswordHash,
|
||||
&i.Role,
|
||||
&i.DomainID,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getImcUserByUsername = `-- name: GetImcUserByUsername :one
|
||||
SELECT id, username, password_hash, role, domain_id, created_at FROM imc_users WHERE username = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetImcUserByUsername(ctx context.Context, username string) (ImcUser, error) {
|
||||
row := q.db.QueryRowContext(ctx, getImcUserByUsername, username)
|
||||
var i ImcUser
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Username,
|
||||
&i.PasswordHash,
|
||||
&i.Role,
|
||||
&i.DomainID,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUsersForDomain = `-- name: GetUsersForDomain :many
|
||||
SELECT imc_users.id, imc_users.username, imc_users.password_hash, imc_users.role, imc_users.domain_id, imc_users.created_at FROM imc_users WHERE domain_id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetUsersForDomain(ctx context.Context, domainID uint32) ([]ImcUser, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getUsersForDomain, domainID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ImcUser
|
||||
for rows.Next() {
|
||||
var i ImcUser
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Username,
|
||||
&i.PasswordHash,
|
||||
&i.Role,
|
||||
&i.DomainID,
|
||||
&i.CreatedAt,
|
||||
); 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 getUsersForDomainViaJoin = `-- name: GetUsersForDomainViaJoin :many
|
||||
SELECT imc_users.id, imc_users.username, imc_users.password_hash, imc_users.role, imc_users.domain_id, imc_users.created_at FROM imc_users
|
||||
JOIN imc_users2domains ON imc_users.id = imc_users2domains.user_id
|
||||
WHERE imc_users2domains.domain_id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetUsersForDomainViaJoin(ctx context.Context, domainID uint32) ([]ImcUser, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getUsersForDomainViaJoin, domainID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ImcUser
|
||||
for rows.Next() {
|
||||
var i ImcUser
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Username,
|
||||
&i.PasswordHash,
|
||||
&i.Role,
|
||||
&i.DomainID,
|
||||
&i.CreatedAt,
|
||||
); 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 isUserInDomain = `-- name: IsUserInDomain :one
|
||||
SELECT COUNT(*) as count FROM imc_users2domains WHERE user_id = ? AND domain_id = ?
|
||||
`
|
||||
|
||||
type IsUserInDomainParams struct {
|
||||
UserID uint32 `json:"user_id"`
|
||||
DomainID uint32 `json:"domain_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) IsUserInDomain(ctx context.Context, arg IsUserInDomainParams) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, isUserInDomain, arg.UserID, arg.DomainID)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const removeUserFromDomain = `-- name: RemoveUserFromDomain :exec
|
||||
DELETE FROM imc_users2domains WHERE user_id = ? AND domain_id = ?
|
||||
`
|
||||
|
||||
type RemoveUserFromDomainParams struct {
|
||||
UserID uint32 `json:"user_id"`
|
||||
DomainID uint32 `json:"domain_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) RemoveUserFromDomain(ctx context.Context, arg RemoveUserFromDomainParams) error {
|
||||
_, err := q.db.ExecContext(ctx, removeUserFromDomain, arg.UserID, arg.DomainID)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateImcUserPassword = `-- name: UpdateImcUserPassword :exec
|
||||
UPDATE imc_users SET password_hash = ? WHERE id = ?
|
||||
`
|
||||
|
||||
type UpdateImcUserPasswordParams struct {
|
||||
PasswordHash string `json:"password_hash"`
|
||||
ID uint32 `json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateImcUserPassword(ctx context.Context, arg UpdateImcUserPasswordParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateImcUserPassword, arg.PasswordHash, arg.ID)
|
||||
return err
|
||||
}
|
||||
98
backend/internal/db/sqlc/models.go
Normal file
98
backend/internal/db/sqlc/models.go
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ImcUsersRole string
|
||||
|
||||
const (
|
||||
ImcUsersRoleAdmin ImcUsersRole = "admin"
|
||||
ImcUsersRoleUser ImcUsersRole = "user"
|
||||
)
|
||||
|
||||
func (e *ImcUsersRole) Scan(src interface{}) error {
|
||||
switch s := src.(type) {
|
||||
case []byte:
|
||||
*e = ImcUsersRole(s)
|
||||
case string:
|
||||
*e = ImcUsersRole(s)
|
||||
default:
|
||||
return fmt.Errorf("unsupported scan type for ImcUsersRole: %T", src)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type NullImcUsersRole struct {
|
||||
ImcUsersRole ImcUsersRole `json:"imc_users_role"`
|
||||
Valid bool `json:"valid"` // Valid is true if ImcUsersRole is not NULL
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (ns *NullImcUsersRole) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
ns.ImcUsersRole, ns.Valid = "", false
|
||||
return nil
|
||||
}
|
||||
ns.Valid = true
|
||||
return ns.ImcUsersRole.Scan(value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (ns NullImcUsersRole) Value() (driver.Value, error) {
|
||||
if !ns.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return string(ns.ImcUsersRole), nil
|
||||
}
|
||||
|
||||
type ImcLoginAttempt struct {
|
||||
ID uint32 `json:"id"`
|
||||
Username string `json:"username"`
|
||||
IpAddress string `json:"ip_address"`
|
||||
AttemptedAt sql.NullTime `json:"attempted_at"`
|
||||
Successful sql.NullBool `json:"successful"`
|
||||
}
|
||||
|
||||
type ImcUser struct {
|
||||
ID uint32 `json:"id"`
|
||||
Username string `json:"username"`
|
||||
PasswordHash string `json:"password_hash"`
|
||||
Role NullImcUsersRole `json:"role"`
|
||||
DomainID uint32 `json:"domain_id"`
|
||||
CreatedAt sql.NullTime `json:"created_at"`
|
||||
}
|
||||
|
||||
type ImcUsers2domain struct {
|
||||
ID uint32 `json:"id"`
|
||||
UserID uint32 `json:"user_id"`
|
||||
DomainID uint32 `json:"domain_id"`
|
||||
CreatedAt sql.NullTime `json:"created_at"`
|
||||
}
|
||||
|
||||
type VirtualAlias struct {
|
||||
ID uint32 `json:"id"`
|
||||
DomainID uint32 `json:"domain_id"`
|
||||
Source string `json:"source"`
|
||||
Destination string `json:"destination"`
|
||||
}
|
||||
|
||||
type VirtualDomain struct {
|
||||
ID uint32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
CreatedAt sql.NullTime `json:"created_at"`
|
||||
}
|
||||
|
||||
type VirtualUser struct {
|
||||
ID uint32 `json:"id"`
|
||||
DomainID uint32 `json:"domain_id"`
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
Quota sql.NullInt64 `json:"quota"`
|
||||
}
|
||||
180
backend/internal/db/sqlc/users.sql.go
Normal file
180
backend/internal/db/sqlc/users.sql.go
Normal file
|
|
@ -0,0 +1,180 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: users.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
const countUsersByDomain = `-- name: CountUsersByDomain :one
|
||||
SELECT COUNT(*) as count FROM virtual_users WHERE domain_id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) CountUsersByDomain(ctx context.Context, domainID uint32) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, countUsersByDomain, domainID)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const createUser = `-- name: CreateUser :exec
|
||||
INSERT INTO virtual_users (domain_id, email, password, quota) VALUES (?, ?, ?, ?)
|
||||
`
|
||||
|
||||
type CreateUserParams struct {
|
||||
DomainID uint32 `json:"domain_id"`
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
Quota sql.NullInt64 `json:"quota"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) error {
|
||||
_, err := q.db.ExecContext(ctx, createUser,
|
||||
arg.DomainID,
|
||||
arg.Email,
|
||||
arg.Password,
|
||||
arg.Quota,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteUser = `-- name: DeleteUser :exec
|
||||
DELETE FROM virtual_users WHERE id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteUser(ctx context.Context, id uint32) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteUser, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const getAllMailUsers = `-- name: GetAllMailUsers :many
|
||||
SELECT id, domain_id, email, password, quota FROM virtual_users
|
||||
`
|
||||
|
||||
func (q *Queries) GetAllMailUsers(ctx context.Context) ([]VirtualUser, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getAllMailUsers)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []VirtualUser
|
||||
for rows.Next() {
|
||||
var i VirtualUser
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.DomainID,
|
||||
&i.Email,
|
||||
&i.Password,
|
||||
&i.Quota,
|
||||
); 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 getUserByEmail = `-- name: GetUserByEmail :one
|
||||
SELECT id, domain_id, email, password, quota FROM virtual_users WHERE email = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetUserByEmail(ctx context.Context, email string) (VirtualUser, error) {
|
||||
row := q.db.QueryRowContext(ctx, getUserByEmail, email)
|
||||
var i VirtualUser
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.DomainID,
|
||||
&i.Email,
|
||||
&i.Password,
|
||||
&i.Quota,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserByID = `-- name: GetUserByID :one
|
||||
SELECT id, domain_id, email, password, quota FROM virtual_users WHERE id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetUserByID(ctx context.Context, id uint32) (VirtualUser, error) {
|
||||
row := q.db.QueryRowContext(ctx, getUserByID, id)
|
||||
var i VirtualUser
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.DomainID,
|
||||
&i.Email,
|
||||
&i.Password,
|
||||
&i.Quota,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUsersByDomain = `-- name: GetUsersByDomain :many
|
||||
SELECT id, domain_id, email, password, quota FROM virtual_users WHERE domain_id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetUsersByDomain(ctx context.Context, domainID uint32) ([]VirtualUser, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getUsersByDomain, domainID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []VirtualUser
|
||||
for rows.Next() {
|
||||
var i VirtualUser
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.DomainID,
|
||||
&i.Email,
|
||||
&i.Password,
|
||||
&i.Quota,
|
||||
); 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 updateUserPassword = `-- name: UpdateUserPassword :exec
|
||||
UPDATE virtual_users SET password = ? WHERE id = ?
|
||||
`
|
||||
|
||||
type UpdateUserPasswordParams struct {
|
||||
Password string `json:"password"`
|
||||
ID uint32 `json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateUserPassword(ctx context.Context, arg UpdateUserPasswordParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateUserPassword, arg.Password, arg.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateUserQuota = `-- name: UpdateUserQuota :exec
|
||||
UPDATE virtual_users SET quota = ? WHERE id = ?
|
||||
`
|
||||
|
||||
type UpdateUserQuotaParams struct {
|
||||
Quota sql.NullInt64 `json:"quota"`
|
||||
ID uint32 `json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateUserQuota(ctx context.Context, arg UpdateUserQuotaParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateUserQuota, arg.Quota, arg.ID)
|
||||
return err
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue