Documentation
¶
Index ¶
- func ContextWithTransaction(ctx context.Context, tx *gorm.DB) context.Context
- func InitDefaultTenant(db *gorm.DB) error
- func TransactionFromContext(ctx context.Context) *gorm.DB
- type Database
- type Message
- type MySQL
- func (db *MySQL) AddUserToTenant(ctx context.Context, userID, tenantID uint) error
- func (db *MySQL) Close() error
- func (db *MySQL) CreateSession(ctx context.Context, sessionId string) error
- func (db *MySQL) CreateTenant(ctx context.Context, tenant *Tenant) error
- func (db *MySQL) CreateUser(ctx context.Context, user *User) error
- func (db *MySQL) DeleteSession(ctx context.Context, sessionID string) error
- func (db *MySQL) DeleteTenant(ctx context.Context, id uint) error
- func (db *MySQL) DeleteUser(ctx context.Context, id uint) error
- func (db *MySQL) DeleteUserTenants(ctx context.Context, userID uint) error
- func (db *MySQL) GetMessages(ctx context.Context, sessionID string) ([]*Message, error)
- func (db *MySQL) GetMessagesWithPagination(ctx context.Context, sessionID string, page, pageSize int) ([]*Message, error)
- func (db *MySQL) GetSessions(ctx context.Context) ([]*Session, error)
- func (db *MySQL) GetTenantByID(ctx context.Context, id uint) (*Tenant, error)
- func (db *MySQL) GetTenantByName(ctx context.Context, name string) (*Tenant, error)
- func (db *MySQL) GetTenantUsers(ctx context.Context, tenantID uint) ([]*User, error)
- func (db *MySQL) GetUserByUsername(ctx context.Context, username string) (*User, error)
- func (db *MySQL) GetUserTenants(ctx context.Context, userID uint) ([]*Tenant, error)
- func (db *MySQL) ListTenants(ctx context.Context) ([]*Tenant, error)
- func (db *MySQL) ListUsers(ctx context.Context) ([]*User, error)
- func (db *MySQL) RemoveUserFromTenant(ctx context.Context, userID, tenantID uint) error
- func (db *MySQL) SaveMessage(ctx context.Context, message *Message) error
- func (db *MySQL) SessionExists(ctx context.Context, sessionID string) (bool, error)
- func (db *MySQL) Transaction(ctx context.Context, fn func(ctx context.Context) error) error
- func (db *MySQL) UpdateSessionTitle(ctx context.Context, sessionID string, title string) error
- func (db *MySQL) UpdateTenant(ctx context.Context, tenant *Tenant) error
- func (db *MySQL) UpdateUser(ctx context.Context, user *User) error
- type Postgres
- func (db *Postgres) AddUserToTenant(ctx context.Context, userID, tenantID uint) error
- func (db *Postgres) Close() error
- func (db *Postgres) CreateSession(ctx context.Context, sessionId string) error
- func (db *Postgres) CreateTenant(ctx context.Context, tenant *Tenant) error
- func (db *Postgres) CreateUser(ctx context.Context, user *User) error
- func (db *Postgres) DeleteSession(ctx context.Context, sessionID string) error
- func (db *Postgres) DeleteTenant(ctx context.Context, id uint) error
- func (db *Postgres) DeleteUser(ctx context.Context, id uint) error
- func (db *Postgres) DeleteUserTenants(ctx context.Context, userID uint) error
- func (db *Postgres) GetMessages(ctx context.Context, sessionID string) ([]*Message, error)
- func (db *Postgres) GetMessagesWithPagination(ctx context.Context, sessionID string, page, pageSize int) ([]*Message, error)
- func (db *Postgres) GetSessions(ctx context.Context) ([]*Session, error)
- func (db *Postgres) GetTenantByID(ctx context.Context, id uint) (*Tenant, error)
- func (db *Postgres) GetTenantByName(ctx context.Context, name string) (*Tenant, error)
- func (db *Postgres) GetTenantUsers(ctx context.Context, tenantID uint) ([]*User, error)
- func (db *Postgres) GetUserByUsername(ctx context.Context, username string) (*User, error)
- func (db *Postgres) GetUserTenants(ctx context.Context, userID uint) ([]*Tenant, error)
- func (db *Postgres) ListTenants(ctx context.Context) ([]*Tenant, error)
- func (db *Postgres) ListUsers(ctx context.Context) ([]*User, error)
- func (db *Postgres) RemoveUserFromTenant(ctx context.Context, userID, tenantID uint) error
- func (db *Postgres) SaveMessage(ctx context.Context, message *Message) error
- func (db *Postgres) SessionExists(ctx context.Context, sessionID string) (bool, error)
- func (db *Postgres) Transaction(ctx context.Context, fn func(ctx context.Context) error) error
- func (db *Postgres) UpdateSessionTitle(ctx context.Context, sessionID string, title string) error
- func (db *Postgres) UpdateTenant(ctx context.Context, tenant *Tenant) error
- func (db *Postgres) UpdateUser(ctx context.Context, user *User) error
- type SQLite
- func (db *SQLite) AddUserToTenant(ctx context.Context, userID, tenantID uint) error
- func (db *SQLite) Close() error
- func (db *SQLite) CreateSession(ctx context.Context, sessionId string) error
- func (db *SQLite) CreateTenant(ctx context.Context, tenant *Tenant) error
- func (db *SQLite) CreateUser(ctx context.Context, user *User) error
- func (db *SQLite) DeleteSession(ctx context.Context, sessionID string) error
- func (db *SQLite) DeleteTenant(ctx context.Context, id uint) error
- func (db *SQLite) DeleteUser(ctx context.Context, id uint) error
- func (db *SQLite) DeleteUserTenants(ctx context.Context, userID uint) error
- func (db *SQLite) GetMessages(ctx context.Context, sessionID string) ([]*Message, error)
- func (db *SQLite) GetMessagesWithPagination(ctx context.Context, sessionID string, page, pageSize int) ([]*Message, error)
- func (db *SQLite) GetSessions(ctx context.Context) ([]*Session, error)
- func (db *SQLite) GetTenantByID(ctx context.Context, id uint) (*Tenant, error)
- func (db *SQLite) GetTenantByName(ctx context.Context, name string) (*Tenant, error)
- func (db *SQLite) GetTenantUsers(ctx context.Context, tenantID uint) ([]*User, error)
- func (db *SQLite) GetUserByUsername(ctx context.Context, username string) (*User, error)
- func (db *SQLite) GetUserTenants(ctx context.Context, userID uint) ([]*Tenant, error)
- func (db *SQLite) ListTenants(ctx context.Context) ([]*Tenant, error)
- func (db *SQLite) ListUsers(ctx context.Context) ([]*User, error)
- func (db *SQLite) RemoveUserFromTenant(ctx context.Context, userID, tenantID uint) error
- func (db *SQLite) SaveMessage(ctx context.Context, message *Message) error
- func (db *SQLite) SessionExists(ctx context.Context, sessionID string) (bool, error)
- func (db *SQLite) Transaction(ctx context.Context, fn func(ctx context.Context) error) error
- func (db *SQLite) UpdateSessionTitle(ctx context.Context, sessionID string, title string) error
- func (db *SQLite) UpdateTenant(ctx context.Context, tenant *Tenant) error
- func (db *SQLite) UpdateUser(ctx context.Context, user *User) error
- type Session
- type Tenant
- type User
- type UserRole
- type UserTenant
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithTransaction ¶
ContextWithTransaction creates a context containing a transaction
func InitDefaultTenant ¶
InitDefaultTenant initializes the default tenant if it doesn't exist
Types ¶
type Database ¶
type Database interface {
// Close closes the database connection.
Close() error
// SaveMessage saves a message to the database.
SaveMessage(ctx context.Context, message *Message) error
// GetMessages gets messages for a specific session.
GetMessages(ctx context.Context, sessionID string) ([]*Message, error)
// GetMessagesWithPagination gets messages for a specific session with pagination.
GetMessagesWithPagination(ctx context.Context, sessionID string, page, pageSize int) ([]*Message, error)
// CreateSession creates a new session with the given sessionId.
CreateSession(ctx context.Context, sessionId string) error
// SessionExists checks if a session exists.
SessionExists(ctx context.Context, sessionID string) (bool, error)
// GetSessions gets all chat sessions with their latest message.
GetSessions(ctx context.Context) ([]*Session, error)
// UpdateSessionTitle updates the title of a session.
UpdateSessionTitle(ctx context.Context, sessionID string, title string) error
// DeleteSession deletes a session by ID.
DeleteSession(ctx context.Context, sessionID string) error
CreateUser(ctx context.Context, user *User) error
GetUserByUsername(ctx context.Context, username string) (*User, error)
UpdateUser(ctx context.Context, user *User) error
DeleteUser(ctx context.Context, id uint) error
ListUsers(ctx context.Context) ([]*User, error)
CreateTenant(ctx context.Context, tenant *Tenant) error
GetTenantByName(ctx context.Context, name string) (*Tenant, error)
GetTenantByID(ctx context.Context, id uint) (*Tenant, error)
UpdateTenant(ctx context.Context, tenant *Tenant) error
DeleteTenant(ctx context.Context, id uint) error
ListTenants(ctx context.Context) ([]*Tenant, error)
AddUserToTenant(ctx context.Context, userID, tenantID uint) error
RemoveUserFromTenant(ctx context.Context, userID, tenantID uint) error
GetUserTenants(ctx context.Context, userID uint) ([]*Tenant, error)
GetTenantUsers(ctx context.Context, tenantID uint) ([]*User, error)
DeleteUserTenants(ctx context.Context, userID uint) error
Transaction(ctx context.Context, fn func(ctx context.Context) error) error
}
Database defines the methods for database operations.
func NewDatabase ¶
func NewDatabase(cfg *config.DatabaseConfig) (Database, error)
NewDatabase creates a new database based on configuration
func NewMySQL ¶
func NewMySQL(cfg *config.DatabaseConfig) (Database, error)
NewMySQL creates a new MySQL instance
func NewPostgres ¶
func NewPostgres(cfg *config.DatabaseConfig) (Database, error)
NewPostgres creates a new Postgres instance
type Message ¶
type Message struct {
ID string `json:"id"`
SessionID string `json:"session_id"`
Content string `json:"content"`
Sender string `json:"sender"`
Timestamp time.Time `json:"timestamp"`
ToolCalls string `json:"toolCalls,omitempty"`
ToolResult string `json:"toolResult,omitempty"`
}
Message represents a chat message
type MySQL ¶
type MySQL struct {
// contains filtered or unexported fields
}
MySQL implements the Database interface using MySQL
func (*MySQL) AddUserToTenant ¶
AddUserToTenant adds a user to a tenant
func (*MySQL) CreateSession ¶
func (*MySQL) CreateTenant ¶
CreateTenant creates a new tenant
func (*MySQL) CreateUser ¶
CreateUser creates a new user
func (*MySQL) DeleteSession ¶
DeleteSession deletes a session by ID
func (*MySQL) DeleteTenant ¶
DeleteTenant deletes a tenant by ID
func (*MySQL) DeleteUser ¶
DeleteUser deletes a user by ID
func (*MySQL) DeleteUserTenants ¶
DeleteUserTenants deletes all tenant associations for a user
func (*MySQL) GetMessages ¶
func (*MySQL) GetMessagesWithPagination ¶
func (*MySQL) GetTenantByID ¶
GetTenantByID retrieves a tenant by ID
func (*MySQL) GetTenantByName ¶
GetTenantByName retrieves a tenant by name
func (*MySQL) GetTenantUsers ¶
GetTenantUsers gets all users for a tenant
func (*MySQL) GetUserByUsername ¶
GetUserByUsername retrieves a user by username
func (*MySQL) GetUserTenants ¶
GetUserTenants gets all tenants for a user
func (*MySQL) ListTenants ¶
ListTenants retrieves all tenants
func (*MySQL) RemoveUserFromTenant ¶
RemoveUserFromTenant removes a user from a tenant
func (*MySQL) SaveMessage ¶
func (*MySQL) SessionExists ¶
func (*MySQL) Transaction ¶
Transaction implements Database.Transaction
func (*MySQL) UpdateSessionTitle ¶
func (*MySQL) UpdateTenant ¶
UpdateTenant updates an existing tenant
type Postgres ¶
type Postgres struct {
// contains filtered or unexported fields
}
Postgres implements the Database interface using PostgreSQL
func (*Postgres) AddUserToTenant ¶
AddUserToTenant adds a user to a tenant
func (*Postgres) CreateSession ¶
CreateSession creates a new session with the given sessionId
func (*Postgres) CreateTenant ¶
CreateTenant creates a new tenant
func (*Postgres) CreateUser ¶
CreateUser creates a new user
func (*Postgres) DeleteSession ¶
DeleteSession deletes a session by ID
func (*Postgres) DeleteTenant ¶
DeleteTenant deletes a tenant by ID
func (*Postgres) DeleteUser ¶
DeleteUser deletes a user by ID
func (*Postgres) DeleteUserTenants ¶
DeleteUserTenants deletes all tenant associations for a user
func (*Postgres) GetMessages ¶
GetMessages retrieves all messages for a session
func (*Postgres) GetMessagesWithPagination ¶
func (db *Postgres) GetMessagesWithPagination(ctx context.Context, sessionID string, page, pageSize int) ([]*Message, error)
GetMessagesWithPagination retrieves messages for a specific session with pagination
func (*Postgres) GetSessions ¶
GetSessions retrieves all chat sessions with their latest message
func (*Postgres) GetTenantByID ¶
GetTenantByID retrieves a tenant by ID
func (*Postgres) GetTenantByName ¶
GetTenantByName retrieves a tenant by name
func (*Postgres) GetTenantUsers ¶
GetTenantUsers gets all users for a tenant
func (*Postgres) GetUserByUsername ¶
GetUserByUsername retrieves a user by username
func (*Postgres) GetUserTenants ¶
GetUserTenants gets all tenants for a user
func (*Postgres) ListTenants ¶
ListTenants retrieves all tenants
func (*Postgres) RemoveUserFromTenant ¶
RemoveUserFromTenant removes a user from a tenant
func (*Postgres) SaveMessage ¶
SaveMessage saves a message to the database
func (*Postgres) SessionExists ¶
SessionExists checks if a session exists
func (*Postgres) Transaction ¶
Transaction implements Database.Transaction
func (*Postgres) UpdateSessionTitle ¶
UpdateSessionTitle updates the title of a session
func (*Postgres) UpdateTenant ¶
UpdateTenant updates an existing tenant
type SQLite ¶
type SQLite struct {
// contains filtered or unexported fields
}
SQLite implements the Database interface using SQLite
func (*SQLite) AddUserToTenant ¶
AddUserToTenant adds a user to a tenant
func (*SQLite) CreateSession ¶
func (*SQLite) CreateTenant ¶
CreateTenant creates a new tenant
func (*SQLite) CreateUser ¶
CreateUser creates a new user
func (*SQLite) DeleteSession ¶
DeleteSession deletes a session by ID
func (*SQLite) DeleteTenant ¶
DeleteTenant deletes a tenant by ID
func (*SQLite) DeleteUser ¶
DeleteUser deletes a user by ID
func (*SQLite) DeleteUserTenants ¶
DeleteUserTenants deletes all tenant associations for a user
func (*SQLite) GetMessages ¶
func (*SQLite) GetMessagesWithPagination ¶
func (*SQLite) GetTenantByID ¶
GetTenantByID retrieves a tenant by ID
func (*SQLite) GetTenantByName ¶
GetTenantByName retrieves a tenant by name
func (*SQLite) GetTenantUsers ¶
GetTenantUsers gets all users for a tenant
func (*SQLite) GetUserByUsername ¶
GetUserByUsername retrieves a user by username
func (*SQLite) GetUserTenants ¶
GetUserTenants gets all tenants for a user
func (*SQLite) ListTenants ¶
ListTenants retrieves all tenants
func (*SQLite) RemoveUserFromTenant ¶
RemoveUserFromTenant removes a user from a tenant
func (*SQLite) SaveMessage ¶
func (*SQLite) SessionExists ¶
func (*SQLite) Transaction ¶
Transaction implements Database.Transaction
func (*SQLite) UpdateSessionTitle ¶
func (*SQLite) UpdateTenant ¶
UpdateTenant updates an existing tenant
type Session ¶
type Session struct {
ID string `json:"id"`
CreatedAt time.Time `json:"createdAt"`
Title string `json:"title"`
}
Session represents a chat session
type Tenant ¶
type Tenant struct {
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
Name string `json:"name" gorm:"type:varchar(50);uniqueIndex"`
Prefix string `json:"prefix" gorm:"type:varchar(50);uniqueIndex"`
Description string `json:"description" gorm:"type:varchar(255)"`
IsActive bool `json:"isActive" gorm:"not null;default:true"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
Tenant represents a tenant in the system
type User ¶
type User struct {
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
Username string `json:"username" gorm:"type:varchar(50);uniqueIndex"`
Password string `json:"-" gorm:"not null"` // Password is not exposed in JSON
Role UserRole `json:"role" gorm:"not null;default:'normal'"`
IsActive bool `json:"isActive" gorm:"not null;default:true"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
User represents an admin user
type UserTenant ¶
type UserTenant struct {
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
UserID uint `json:"userId" gorm:"index:idx_user_tenant,unique;not null"`
TenantID uint `json:"tenantId" gorm:"index:idx_user_tenant,unique;not null"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
UserTenant represents the relationship between a user and a tenant