summaryrefslogtreecommitdiff
path: root/db/endpoint.go
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-05-13 22:32:24 -0500
committersanine <sanine.not@pm.me>2023-05-13 22:32:24 -0500
commit9571ccc4d87907067df98edeaa78f0c167fcff43 (patch)
treee64760fa34d7ecfd8460596b8ddf314ceacda2b7 /db/endpoint.go
parent609ef3f3b4d4cb355d80b19df1e91db258b0bbe0 (diff)
begin total refactor
Diffstat (limited to 'db/endpoint.go')
-rw-r--r--db/endpoint.go96
1 files changed, 0 insertions, 96 deletions
diff --git a/db/endpoint.go b/db/endpoint.go
deleted file mode 100644
index d880510..0000000
--- a/db/endpoint.go
+++ /dev/null
@@ -1,96 +0,0 @@
-package db
-
-func (p *Phlox) CreateEndpoint(name, path, address string) (Endpoint, error) {
- var id int
- row := p.db.QueryRow("select coalesce(max(endpointid), 0) from endpoints;")
- err := row.Scan(&id)
- if err != nil {
- return Endpoint{}, err
- }
- id += 1
-
- _, err = p.db.Exec(
- "insert into endpoints values (?, ?, ?, ?)",
- id, name, path, address,
- )
- if err != nil {
- return Endpoint{}, err
- }
-
- endpoint := Endpoint{
- Id: id,
- Name: name,
- Path: path,
- Address: address,
- }
-
- return endpoint, nil
-}
-
-
-func (p *Phlox) DeleteEndpoint(endpoint Endpoint) error {
- _, err := p.db.Exec("delete from endpoints where endpointid = ?;", endpoint.Id)
- return err
-}
-
-
-func extractEndpoint(s Scanner) (Endpoint, error) {
- var endpoint Endpoint
- err := s.Scan(
- &endpoint.Id,
- &endpoint.Name,
- &endpoint.Path,
- &endpoint.Address,
- )
- return endpoint, err
-}
-
-
-func (p *Phlox) SetEndpointPath(endpoint Endpoint, path string) error {
- _, err := p.db.Exec("update endpoints set path=? where endpointid=?", path, endpoint.Id)
- return err
-}
-
-func (p *Phlox) SetEndpointAddress(endpoint Endpoint, address string) error {
- _, err := p.db.Exec("update endpoints set address=? where endpointid=?", address, endpoint.Id)
- return err
-}
-
-
-func queryEndpoint(p *Phlox, query, param string) (Endpoint, error) {
- row := p.db.QueryRow(query, param)
- endpoint, err := extractEndpoint(row)
- return endpoint, err
-}
-
-func (p *Phlox) GetEndpointByName(name string) (Endpoint, error) {
- return queryEndpoint(p, "select * from endpoints where name = ?;", name)
-}
-
-func (p *Phlox) GetEndpointByPath(path string) (Endpoint, error) {
- return queryEndpoint(p, "select * from endpoints where path = ?;", path)
-}
-
-func (p *Phlox) GetEndpointByAddress(address string) (Endpoint, error) {
- return queryEndpoint(p, "select * from endpoints where address = ?;", address)
-}
-
-
-func (p *Phlox) AllEndpoints() ([]Endpoint, error) {
- endpoints := make([]Endpoint, 0)
- rows, err := p.db.Query("select * from endpoints;")
- if err != nil {
- return endpoints, err
- }
- defer rows.Close()
-
- for rows.Next() {
- endpoint, err := extractEndpoint(rows)
- if err != nil {
- return endpoints, err
- }
- endpoints = append(endpoints, endpoint)
- }
-
- return endpoints, nil
-}