api-cds-search/cmd/database/table/cdsView.go

71 lines
2.0 KiB
Go
Raw Normal View History

2025-03-24 08:22:43 +00:00
/*
Copyright (C) 2025 snoutie
Authors: snoutie (copyright@achtarmig.org)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2025-03-24 07:50:01 +00:00
package table
import (
2025-03-24 09:01:47 +00:00
"api-cds-search/cmd/database"
2025-03-24 07:50:01 +00:00
_ "embed"
)
type CDSView struct {
2025-05-20 18:41:26 +00:00
TechnicalName `json:"Name"`
DisplayName `json:"DisplayName"`
Description `json:"Description"`
Version `json:"Version"`
State `json:"State"`
CreatedAt `json:"CreatedAt"`
ModifiedAt `json:"ModifiedAt"`
2025-03-24 07:50:01 +00:00
}
//go:embed sql/query_cds_view.sql
var query_cds_view string
2025-05-20 18:41:26 +00:00
func GetCDSView(TechnicalName TechnicalName) (*CDSView, error) {
2025-03-24 07:50:01 +00:00
row := database.DB.QueryRow(query_cds_view, TechnicalName)
var CDSView CDSView
err := row.Scan(&CDSView.TechnicalName, &CDSView.DisplayName, &CDSView.Description, &CDSView.Version, &CDSView.State, &CDSView.CreatedAt, &CDSView.ModifiedAt)
if err != nil {
return nil, err
}
return &CDSView, nil
}
//go:embed sql/query_all_cds_view_technical_names.sql
var query_all_cds_view_technical_names string
2025-05-20 18:41:26 +00:00
func QueryAllCDSViewTechnicalNames() (*[]TechnicalName, error) {
2025-03-24 07:50:01 +00:00
rows, err := database.DB.Query(query_all_cds_view_technical_names)
if err != nil {
return nil, err
}
2025-05-20 18:41:26 +00:00
var technicalNames []TechnicalName
2025-03-24 07:50:01 +00:00
for rows.Next() {
2025-05-20 18:41:26 +00:00
var technicalName TechnicalName
2025-03-24 07:50:01 +00:00
err := rows.Scan(&technicalName)
if err != nil {
return nil, err
}
technicalNames = append(technicalNames, technicalName)
}
return &technicalNames, nil
}