mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-21 07:01:41 +03:00
26f0c9a381
* 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`.
67 lines
1.5 KiB
Go
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()
|
|
}
|