NewRepo (repos.go)

9router-go · api-key-management, sql-repository, crud-operations, connection-validation, database, provider-connections

SQL database repository for managing API keys and provider connections with validation and CRUD operations.

// Source: https://github.com/luqman-v1/9router-go | License: MIT | Copyright 2024-2026 decolua and contributors
// Provided via justclaw.it.com; keep this notice with the code.
package db

import (
	"database/sql"
	"encoding/json"
	"fmt"
	"strings"
	"time"

	"9router/proxy/internal/models"
)

type Repo struct {
	db *sql.DB
}

// NewRepo creates a new repository instance using the provided SQL database connection.
func NewRepo(db *sql.DB) *Repo {
	return &Repo{db: db}
}

// RawDB returns the underlying *sql.DB connection for direct queries.
func (r *Repo) RawDB() *sql.DB {
	return r.db
}

// ValidateApiKey checks if the given API key exists and is active.
func (r *Repo) ValidateApiKey(key string) (bool, error) {
	var active int
	err := r.db.QueryRow("SELECT isActive FROM apiKeys WHERE key 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key