hatecomputers.club/database/dns.go

41 lines
806 B
Go

package database
import (
"database/sql"
_ "github.com/mattn/go-sqlite3"
"log"
"time"
)
type DNSRecord struct {
ID string
UserID string
Name string
Type string
Content string
TTL int
CreatedAt time.Time
}
func GetUserDNSRecords(db *sql.DB, userID string) ([]DNSRecord, error) {
log.Println("getting dns records for user", userID)
rows, err := db.Query("SELECT * FROM dns_records WHERE user_id = ?", userID)
if err != nil {
return nil, err
}
defer rows.Close()
var records []DNSRecord
for rows.Next() {
var record DNSRecord
err := rows.Scan(&record.ID, &record.UserID, &record.Name, &record.Type, &record.Content, &record.TTL, &record.CreatedAt)
if err != nil {
return nil, err
}
records = append(records, record)
}
return records, nil
}