dal

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetExternalIdentityDB

func GetExternalIdentityDB(ctx context.Context, defDB *gorm.DB) *gorm.DB

func GetLoggerDB

func GetLoggerDB(ctx context.Context, defDB *gorm.DB) *gorm.DB

Get logger storage instance

func GetMenuDB

func GetMenuDB(ctx context.Context, defDB *gorm.DB) *gorm.DB

Get menu storage instance

func GetMenuResourceDB

func GetMenuResourceDB(ctx context.Context, defDB *gorm.DB) *gorm.DB

Get menu resource storage instance

func GetRoleDB

func GetRoleDB(ctx context.Context, defDB *gorm.DB) *gorm.DB

Get role storage instance

func GetRoleMenuDB

func GetRoleMenuDB(ctx context.Context, defDB *gorm.DB) *gorm.DB

Get role menu storage instance

func GetTenantDB

func GetTenantDB(ctx context.Context, defDB *gorm.DB) *gorm.DB

Get tenant storage instance

func GetTenantEndpointDB

func GetTenantEndpointDB(ctx context.Context, defDB *gorm.DB) *gorm.DB

GetTenantEndpointDB 获取租户-端点关联表 DB 实例

func GetTenantModelDB

func GetTenantModelDB(ctx context.Context, defDB *gorm.DB) *gorm.DB

Get tenant_model storage instance

func GetUserAPIKeyDB

func GetUserAPIKeyDB(ctx context.Context, defDB *gorm.DB) *gorm.DB

GetUserAPIKeyDB 获取 API Key 表的数据库实例并关联 Model

func GetUserDB

func GetUserDB(ctx context.Context, defDB *gorm.DB) *gorm.DB

Get user storage instance

func GetUserRoleDB

func GetUserRoleDB(ctx context.Context, defDB *gorm.DB) *gorm.DB

Get user role storage instance

Types

type ExternalIdentity

type ExternalIdentity struct {
	DB *gorm.DB
}

func (*ExternalIdentity) Create

func (*ExternalIdentity) GetByProviderUserID

func (a *ExternalIdentity) GetByProviderUserID(ctx context.Context, provider, providerUserID string) (*schema.ExternalIdentity, error)

func (*ExternalIdentity) UpdateSnapshot

func (a *ExternalIdentity) UpdateSnapshot(ctx context.Context, item *schema.ExternalIdentity) error

type Logger

type Logger struct {
	DB *gorm.DB
}

Logger management

func (*Logger) Query

Query loggers from the database based on the provided parameters and options.

type Menu struct {
	DB *gorm.DB
}

Menu management for RBAC

func (a *Menu) Create(ctx context.Context, item *schema.Menu) error

Create a new menu.

func (a *Menu) Delete(ctx context.Context, id string) error

Delete the specified menu from the database.

func (a *Menu) Exists(ctx context.Context, id string) (bool, error)

Checks if the specified menu exists in the database.

func (a *Menu) ExistsCodeByParentID(ctx context.Context, code, parentID string) (bool, error)

Checks if a menu with the specified `code` exists under the specified `parentID` in the database.

func (a *Menu) ExistsNameByParentID(ctx context.Context, name, parentID string) (bool, error)

Checks if a menu with the specified `name` exists under the specified `parentID` in the database.

func (a *Menu) Get(ctx context.Context, id string, opts ...schema.MenuQueryOptions) (*schema.Menu, error)

Get the specified menu from the database.

func (a *Menu) GetByCodeAndParentID(ctx context.Context, code, parentID string, opts ...schema.MenuQueryOptions) (*schema.Menu, error)
func (a *Menu) GetByNameAndParentID(ctx context.Context, name, parentID string, opts ...schema.MenuQueryOptions) (*schema.Menu, error)

GetByNameAndParentID get the specified menu from the database.

func (a *Menu) GetUniquePageByCode(ctx context.Context, code string) (*schema.Menu, error)

Query menus from the database based on the provided parameters and options.

func (a *Menu) QueryPagesByCode(ctx context.Context, code string) (schema.Menus, error)
func (a *Menu) Update(ctx context.Context, item *schema.Menu) error

Update the specified menu in the database.

func (a *Menu) UpdateParentPath(ctx context.Context, id, parentPath string) error

Updates the parent path of the specified menu.

func (a *Menu) UpdateStatusByParentPath(ctx context.Context, parentPath, status string) error

Updates the status of all menus whose parent path starts with the provided parent path.

type MenuResource struct {
	DB *gorm.DB
}

Menu resource management for RBAC

func (a *MenuResource) Create(ctx context.Context, item *schema.MenuResource) error

Create a new menu resource.

func (a *MenuResource) Delete(ctx context.Context, id string) error

Delete the specified menu resource from the database.

func (a *MenuResource) DeleteByMenuID(ctx context.Context, menuID string) error

Deletes the menu resource by menu id.

func (a *MenuResource) Exists(ctx context.Context, id string) (bool, error)

Exist checks if the specified menu resource exists in the database.

func (a *MenuResource) ExistsMethodPathByMenuID(ctx context.Context, method, path, menuID string) (bool, error)

ExistsMethodPathByMenuID checks if the specified menu resource exists in the database.

Get the specified menu resource from the database.

Query menu resources from the database based on the provided parameters and options.

func (a *MenuResource) Update(ctx context.Context, item *schema.MenuResource) error

Update the specified menu resource in the database.

type Role

type Role struct {
	DB *gorm.DB
}

Role management for RBAC

func (*Role) Create

func (a *Role) Create(ctx context.Context, item *schema.Role) error

Create a new role.

func (*Role) Delete

func (a *Role) Delete(ctx context.Context, id string) error

Delete the specified role from the database.

func (*Role) Exists

func (a *Role) Exists(ctx context.Context, id string) (bool, error)

Exist checks if the specified role exists in the database.

func (*Role) ExistsCode

func (a *Role) ExistsCode(ctx context.Context, code string) (bool, error)

func (*Role) Get

func (a *Role) Get(ctx context.Context, id string, opts ...schema.RoleQueryOptions) (*schema.Role, error)

Get the specified role from the database.

func (*Role) GetByCode

func (a *Role) GetByCode(ctx context.Context, code string, opts ...schema.RoleQueryOptions) (*schema.Role, error)

func (*Role) Query

Query roles from the database based on the provided parameters and options.

func (*Role) Update

func (a *Role) Update(ctx context.Context, item *schema.Role) error

Update the specified role in the database.

type RoleMenu

type RoleMenu struct {
	DB *gorm.DB
}

Role permissions for RBAC

func (*RoleMenu) Create

func (a *RoleMenu) Create(ctx context.Context, item *schema.RoleMenu) error

Create a new role menu.

func (*RoleMenu) Delete

func (a *RoleMenu) Delete(ctx context.Context, id string) error

Delete the specified role menu from the database.

func (*RoleMenu) DeleteByMenuID

func (a *RoleMenu) DeleteByMenuID(ctx context.Context, menuID string) error

Deletes role menus by menu id.

func (*RoleMenu) DeleteByRoleID

func (a *RoleMenu) DeleteByRoleID(ctx context.Context, roleID string) error

Deletes role menus by role id.

func (*RoleMenu) Exists

func (a *RoleMenu) Exists(ctx context.Context, id string) (bool, error)

Exist checks if the specified role menu exists in the database.

func (*RoleMenu) ExistsRoleIDMenuID

func (a *RoleMenu) ExistsRoleIDMenuID(ctx context.Context, roleID, menuID string) (bool, error)

func (*RoleMenu) Get

Get the specified role menu from the database.

func (*RoleMenu) Query

Query role menus from the database based on the provided parameters and options.

func (*RoleMenu) Update

func (a *RoleMenu) Update(ctx context.Context, item *schema.RoleMenu) error

Update the specified role menu in the database.

type Tenant

type Tenant struct {
	DB *gorm.DB
}

Tenant management for RBAC

func (*Tenant) Create

func (a *Tenant) Create(ctx context.Context, item *schema.Tenant) error

Create a new tenant.

func (*Tenant) Delete

func (a *Tenant) Delete(ctx context.Context, id string) error

Delete the specified tenant from the database.

func (*Tenant) Exists

func (a *Tenant) Exists(ctx context.Context, id string) (bool, error)

Exist checks if the specified tenant exists in the database.

func (*Tenant) ExistsCode

func (a *Tenant) ExistsCode(ctx context.Context, code string) (bool, error)

func (*Tenant) Get

func (a *Tenant) Get(ctx context.Context, id string, opts ...schema.TenantQueryOptions) (*schema.Tenant, error)

Get the specified tenant from the database.

func (*Tenant) GetByCode

func (a *Tenant) GetByCode(ctx context.Context, code string, opts ...schema.TenantQueryOptions) (*schema.Tenant, error)

func (*Tenant) Query

Query tenants from the database based on the provided parameters and options.

func (*Tenant) Update

func (a *Tenant) Update(ctx context.Context, item *schema.Tenant) error

Update the specified tenant in the database.

type TenantEndpoint

type TenantEndpoint struct {
	DB *gorm.DB
}

TenantEndpoint RBAC 模块下的租户-端点关联数据访问层

func (*TenantEndpoint) CreateInBatches

func (a *TenantEndpoint) CreateInBatches(ctx context.Context, tx *gorm.DB, items []*schema.TenantEndpoint) error

CreateInBatches 在事务中批量插入端点白名单关联

func (*TenantEndpoint) DeleteByTenantAndModel

func (a *TenantEndpoint) DeleteByTenantAndModel(ctx context.Context, tx *gorm.DB, tenantCode, modelID string) error

DeleteByTenantAndModel 在事务中删除指定租户及模型关联的全部端点白名单。 采用两步执行(先查端点 ID,再用字面量 IN 列表删除)替代 DML 内子查询, 规避 Vitess "subqueries in sharded DML" 限制(Error 1235)。

func (*TenantEndpoint) QueryEndpointIDsByModel

func (a *TenantEndpoint) QueryEndpointIDsByModel(ctx context.Context, tx *gorm.DB, modelID string) ([]string, error)

QueryEndpointIDsByModel 查询指定模型下所有未删除的端点 ID 列表(单表查询)。 单表 SELECT 对 Vitess 分片环境友好,供按模型范围清理/过滤场景复用。

func (*TenantEndpoint) QueryEndpointIDsByTenantAndModel

func (a *TenantEndpoint) QueryEndpointIDsByTenantAndModel(ctx context.Context, tenantCode, modelID string) ([]string, error)

QueryEndpointIDsByTenantAndModel 查询指定租户及模型下已授权的端点 ID 列表。 采用两步查询替代跨表 JOIN:先按模型查出端点 ID,再在租户关联表中按字面量 IN 过滤, 避免 Vitess 分片环境下的跨表 JOIN scatter 风险。

type TenantModel

type TenantModel struct {
	DB *gorm.DB
}

TenantModel management for RBAC

func (*TenantModel) CreateInBatches

func (a *TenantModel) CreateInBatches(ctx context.Context, tx *gorm.DB, items []*schema.TenantModel) error

CreateInBatches inserts a list of bindings inside a transaction.

func (*TenantModel) DeleteByTenantCode

func (a *TenantModel) DeleteByTenantCode(ctx context.Context, tx *gorm.DB, tenantCode string) error

DeleteByTenantCode deletes all bindings of a tenant inside a transaction.

func (*TenantModel) QueryByTenantCode

func (a *TenantModel) QueryByTenantCode(ctx context.Context, tenantCode string) ([]*schema.TenantModel, error)

QueryByTenantCode queries all models associated with the specified tenant.

type User

type User struct {
	DB *gorm.DB
}

User management for RBAC

func (*User) Create

func (a *User) Create(ctx context.Context, item *schema.User) error

Create a new user.

func (*User) Delete

func (a *User) Delete(ctx context.Context, id string) error

Delete the specified user from the database.

func (*User) Exists

func (a *User) Exists(ctx context.Context, id string) (bool, error)

Exist checks if the specified user exists in the database.

func (*User) ExistsUsername

func (a *User) ExistsUsername(ctx context.Context, username string) (bool, error)

func (*User) Get

func (a *User) Get(ctx context.Context, id string, opts ...schema.UserQueryOptions) (*schema.User, error)

Get the specified user from the database.

func (*User) GetByEmail

func (a *User) GetByEmail(ctx context.Context, email string, opts ...schema.UserQueryOptions) (*schema.User, error)

func (*User) GetByUsername

func (a *User) GetByUsername(ctx context.Context, username string, opts ...schema.UserQueryOptions) (*schema.User, error)

func (*User) Query

Query users from the database based on the provided parameters and options.

func (*User) Update

func (a *User) Update(ctx context.Context, item *schema.User, selectFields ...string) error

Update the specified user in the database.

func (*User) UpdatePasswordByID

func (a *User) UpdatePasswordByID(ctx context.Context, id string, password string) error

type UserAPIKey

type UserAPIKey struct {
	DB *gorm.DB
}

UserAPIKey 用户 API Key 的数据持久层结构体

func (*UserAPIKey) Create

func (a *UserAPIKey) Create(ctx context.Context, item *schema.UserAPIKey) error

Create 新增一条记录

func (*UserAPIKey) Delete

func (a *UserAPIKey) Delete(ctx context.Context, id string) error

Delete 逻辑删除记录

func (*UserAPIKey) Exists

func (a *UserAPIKey) Exists(ctx context.Context, id string) (bool, error)

Exists 检查主键 ID 是否存在

func (*UserAPIKey) ExistsAPIKey

func (a *UserAPIKey) ExistsAPIKey(ctx context.Context, apiKey string) (bool, error)

ExistsAPIKey 检查 API Key 字符串是否已存在(避免生成重复的 Key)

func (*UserAPIKey) Get

Get 根据 ID 获取单条 API Key

func (*UserAPIKey) GetByAPIKey

func (a *UserAPIKey) GetByAPIKey(ctx context.Context, apiKey string, opts ...schema.UserAPIKeyQueryOptions) (*schema.UserAPIKey, error)

GetByAPIKey 根据实际的 API Key 字符串获取对应的信息(供精确匹配或校验使用)

func (*UserAPIKey) Query

Query 分页查询用户 API Key

func (*UserAPIKey) Update

func (a *UserAPIKey) Update(ctx context.Context, item *schema.UserAPIKey, selectFields ...string) error

Update 更新记录

type UserRole

type UserRole struct {
	DB *gorm.DB
}

User roles for RBAC

func (*UserRole) Create

func (a *UserRole) Create(ctx context.Context, item *schema.UserRole) error

Create a new user role.

func (*UserRole) Delete

func (a *UserRole) Delete(ctx context.Context, id string) error

Delete the specified user role from the database.

func (*UserRole) DeleteByRoleID

func (a *UserRole) DeleteByRoleID(ctx context.Context, roleID string) error

func (*UserRole) DeleteByUserID

func (a *UserRole) DeleteByUserID(ctx context.Context, userID string) error

func (*UserRole) Exists

func (a *UserRole) Exists(ctx context.Context, id string) (bool, error)

Exist checks if the specified user role exists in the database.

func (*UserRole) Get

Get the specified user role from the database.

func (*UserRole) Query

Query user roles from the database based on the provided parameters and options.

func (*UserRole) Update

func (a *UserRole) Update(ctx context.Context, item *schema.UserRole) error

Update the specified user role in the database.

Jump to

Keyboard shortcuts

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