sq/drivers/userdriver/grip.go
Neil O'Toole 26f0c9a381
Refactor source.Files (#363)
* Moved `source.Files` to its own package, thus the type is now `files.Files`.
* Moved much of the location functionality from pkg `source` to its own package `location`.
2024-01-24 23:29:55 -07:00

67 lines
1.5 KiB
Go

package userdriver
import (
"context"
"database/sql"
"log/slog"
"github.com/neilotoole/sq/libsq/core/lg/lga"
"github.com/neilotoole/sq/libsq/core/lg/lgm"
"github.com/neilotoole/sq/libsq/driver"
"github.com/neilotoole/sq/libsq/source"
"github.com/neilotoole/sq/libsq/source/location"
"github.com/neilotoole/sq/libsq/source/metadata"
)
// grip implements driver.Grip.
type grip struct {
log *slog.Logger
src *source.Source
impl driver.Grip
}
// DB implements driver.Grip.
func (g *grip) DB(ctx context.Context) (*sql.DB, error) {
return g.impl.DB(ctx)
}
// SQLDriver implements driver.Grip.
func (g *grip) SQLDriver() driver.SQLDriver {
return g.impl.SQLDriver()
}
// Source implements driver.Grip.
func (g *grip) Source() *source.Source {
return g.src
}
// TableMetadata implements driver.Grip.
func (g *grip) TableMetadata(ctx context.Context, tblName string) (*metadata.Table, error) {
return g.impl.TableMetadata(ctx, tblName)
}
// SourceMetadata implements driver.Grip.
func (g *grip) SourceMetadata(ctx context.Context, noSchema bool) (*metadata.Source, error) {
meta, err := g.impl.SourceMetadata(ctx, noSchema)
if err != nil {
return nil, err
}
meta.Handle = g.src.Handle
meta.Location = g.src.Location
meta.Name, err = location.Filename(g.src.Location)
if err != nil {
return nil, err
}
meta.FQName = meta.Name
return meta, nil
}
// Close implements driver.Grip.
func (g *grip) Close() error {
g.log.Debug(lgm.CloseDB, lga.Handle, g.src.Handle)
return g.impl.Close()
}