// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.30.0 // source: lms_personas.sql package dbgen import ( "context" "github.com/jackc/pgx/v5/pgtype" ) const CreateLmsPersona = `-- name: CreateLmsPersona :one INSERT INTO lms_personas (name, description, profile_picture, is_active) VALUES ($1, $2, $3, $4) RETURNING id, name, description, profile_picture, is_active, created_at, updated_at ` type CreateLmsPersonaParams struct { Name string `json:"name"` Description pgtype.Text `json:"description"` ProfilePicture pgtype.Text `json:"profile_picture"` IsActive bool `json:"is_active"` } func (q *Queries) CreateLmsPersona(ctx context.Context, arg CreateLmsPersonaParams) (LmsPersona, error) { row := q.db.QueryRow(ctx, CreateLmsPersona, arg.Name, arg.Description, arg.ProfilePicture, arg.IsActive, ) var i LmsPersona err := row.Scan( &i.ID, &i.Name, &i.Description, &i.ProfilePicture, &i.IsActive, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const DeleteLmsPersona = `-- name: DeleteLmsPersona :exec DELETE FROM lms_personas WHERE id = $1 ` func (q *Queries) DeleteLmsPersona(ctx context.Context, id int64) error { _, err := q.db.Exec(ctx, DeleteLmsPersona, id) return err } const GetLmsPersonaByID = `-- name: GetLmsPersonaByID :one SELECT id, name, description, profile_picture, is_active, created_at, updated_at FROM lms_personas WHERE id = $1 ` func (q *Queries) GetLmsPersonaByID(ctx context.Context, id int64) (LmsPersona, error) { row := q.db.QueryRow(ctx, GetLmsPersonaByID, id) var i LmsPersona err := row.Scan( &i.ID, &i.Name, &i.Description, &i.ProfilePicture, &i.IsActive, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const ListLmsPersonas = `-- name: ListLmsPersonas :many SELECT COUNT(*) OVER () AS total_count, p.id, p.name, p.description, p.profile_picture, p.is_active, p.created_at, p.updated_at FROM lms_personas p WHERE ( $3::boolean = FALSE OR p.is_active = TRUE ) ORDER BY p.name ASC, p.created_at DESC LIMIT $1 OFFSET $2 ` type ListLmsPersonasParams struct { Limit int32 `json:"limit"` Offset int32 `json:"offset"` FilterActive bool `json:"filter_active"` } type ListLmsPersonasRow struct { TotalCount int64 `json:"total_count"` ID int64 `json:"id"` Name string `json:"name"` Description pgtype.Text `json:"description"` ProfilePicture pgtype.Text `json:"profile_picture"` IsActive bool `json:"is_active"` CreatedAt pgtype.Timestamptz `json:"created_at"` UpdatedAt pgtype.Timestamptz `json:"updated_at"` } func (q *Queries) ListLmsPersonas(ctx context.Context, arg ListLmsPersonasParams) ([]ListLmsPersonasRow, error) { rows, err := q.db.Query(ctx, ListLmsPersonas, arg.Limit, arg.Offset, arg.FilterActive) if err != nil { return nil, err } defer rows.Close() var items []ListLmsPersonasRow for rows.Next() { var i ListLmsPersonasRow if err := rows.Scan( &i.TotalCount, &i.ID, &i.Name, &i.Description, &i.ProfilePicture, &i.IsActive, &i.CreatedAt, &i.UpdatedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const UpdateLmsPersona = `-- name: UpdateLmsPersona :one UPDATE lms_personas SET name = COALESCE($1::varchar, name), description = COALESCE($2::text, description), profile_picture = COALESCE($3::text, profile_picture), is_active = COALESCE($4::boolean, is_active), updated_at = CURRENT_TIMESTAMP WHERE id = $5 RETURNING id, name, description, profile_picture, is_active, created_at, updated_at ` type UpdateLmsPersonaParams struct { Name pgtype.Text `json:"name"` Description pgtype.Text `json:"description"` ProfilePicture pgtype.Text `json:"profile_picture"` IsActive pgtype.Bool `json:"is_active"` ID int64 `json:"id"` } func (q *Queries) UpdateLmsPersona(ctx context.Context, arg UpdateLmsPersonaParams) (LmsPersona, error) { row := q.db.QueryRow(ctx, UpdateLmsPersona, arg.Name, arg.Description, arg.ProfilePicture, arg.IsActive, arg.ID, ) var i LmsPersona err := row.Scan( &i.ID, &i.Name, &i.Description, &i.ProfilePicture, &i.IsActive, &i.CreatedAt, &i.UpdatedAt, ) return i, err }