37 lines
769 B
Go
37 lines
769 B
Go
package psql
|
|
|
|
import (
|
|
"ymgb/database"
|
|
|
|
"github.com/vinovest/sqlx"
|
|
)
|
|
|
|
type AIModel struct {
|
|
ID string
|
|
Key string
|
|
Name string
|
|
ContextSize int `db:"context_size"`
|
|
}
|
|
|
|
type AIRepository struct {
|
|
db *sqlx.DB
|
|
}
|
|
|
|
func newAiRepository(db *sqlx.DB) AIRepository {
|
|
return AIRepository{db}
|
|
}
|
|
func NewAIRepository(db *database.Context) AIRepository {
|
|
return newAiRepository(db.Postgres)
|
|
}
|
|
|
|
func (rep AIRepository) GetModel(id string) (AIModel, error) {
|
|
model := AIModel{}
|
|
err := rep.db.Get(&model, "SELECT * FROM ai_models WHERE id=$1;", id)
|
|
return model, err
|
|
}
|
|
func (rep AIRepository) GetAllModels() ([]AIModel, error) {
|
|
models := make([]AIModel, 0)
|
|
err := rep.db.Select(&models, "SELECT * FROM ai_models ORDER BY id;")
|
|
return models, err
|
|
}
|