db

package
v0.0.0-...-8928c47 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB wrapper for database connection and operations

func NewDB

func NewDB(config *config.Config, logger *slog.Logger) (*DB, error)

func (*DB) Close

func (db *DB) Close() error

func (*DB) DB

func (db *DB) DB() *bun.DB

type Entity

type Entity struct {
	ID int64 `bun:"id,pk,autoincrement"`
}

type Permission

type Permission struct {
	Entity
	bun.BaseModel `bun:"table:permissions"`

	Name        string  `bun:"name,notnull"`
	Description *string `bun:"description"`
}

type Role

type Role struct {
	Entity
	bun.BaseModel `bun:"table:roles"`

	Name        string  `bun:"name,notnull"`
	Description *string `bun:"description"`
}

type RolePermission

type RolePermission struct {
	bun.BaseModel `bun:"table:role_permissions"`

	RoleID       int64       `bun:"role_id,notnull,pk"`
	PermissionID int64       `bun:"permission_id,notnull,pk"`
	Role         *Role       `bun:"rel:belongs-to,join:role_id=id"`
	Permission   *Permission `bun:"rel:belongs-to,join:permission_id=id"`
}

type Session

type Session struct {
	Entity
	bun.BaseModel `bun:"table:sessions"`

	UserID       int64      `bun:"user_id,notnull"`
	CreatedAt    time.Time  `bun:"created_at,notnull,default:current_timestamp"`
	ExpiresAt    *time.Time `bun:"expires_at"`
	UserAgent    string     `bun:"user_agent,notnull"`
	IP           string     `bun:"ip,notnull"`
	LastActivity time.Time  `bun:"last_activity,notnull,default:current_timestamp"`
}

type User

type User struct {
	Entity
	bun.BaseModel `bun:"table:users"`

	Name         string    `bun:"name,notnull"`
	Username     string    `bun:"username,unique"`
	PhotoURL     *string   `bun:"photo_url"`
	CreatedAt    time.Time `bun:"created_at,notnull,default:current_timestamp"`
	IsDeleted    bool      `bun:"is_deleted,notnull,default:false"`
	IsBlocked    bool      `bun:"is_blocked,notnull,default:false"`
	PasswordHash *string   `bun:"password_hash"`
	Roles        []Role    `bun:"m2m:user_roles,join:User=Role"`
}

type UserRole

type UserRole struct {
	bun.BaseModel `bun:"table:user_roles"`

	UserID int64 `bun:"user_id,notnull,pk"`
	RoleID int64 `bun:"role_id,notnull,pk"`
	User   *User `bun:"rel:belongs-to,join:user_id=id"`
	Role   *Role `bun:"rel:belongs-to,join:role_id=id"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址