mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-18 13:41:49 +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`.
75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
package xlsx
|
|
|
|
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/files"
|
|
"github.com/neilotoole/sq/libsq/source"
|
|
"github.com/neilotoole/sq/libsq/source/drivertype"
|
|
"github.com/neilotoole/sq/libsq/source/location"
|
|
"github.com/neilotoole/sq/libsq/source/metadata"
|
|
)
|
|
|
|
// grip implements driver.Grip. It implements a deferred ingest
|
|
// of the Excel data.
|
|
type grip struct {
|
|
log *slog.Logger
|
|
src *source.Source
|
|
files *files.Files
|
|
dbGrip driver.Grip
|
|
}
|
|
|
|
// DB implements driver.Grip.
|
|
func (g *grip) DB(ctx context.Context) (*sql.DB, error) {
|
|
return g.dbGrip.DB(ctx)
|
|
}
|
|
|
|
// SQLDriver implements driver.Grip.
|
|
func (g *grip) SQLDriver() driver.SQLDriver {
|
|
return g.dbGrip.SQLDriver()
|
|
}
|
|
|
|
// Source implements driver.Grip.
|
|
func (g *grip) Source() *source.Source {
|
|
return g.src
|
|
}
|
|
|
|
// SourceMetadata implements driver.Grip.
|
|
func (g *grip) SourceMetadata(ctx context.Context, noSchema bool) (*metadata.Source, error) {
|
|
md, err := g.dbGrip.SourceMetadata(ctx, noSchema)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
md.Handle = g.src.Handle
|
|
md.Driver = drivertype.XLSX
|
|
md.Location = g.src.Location
|
|
if md.Name, err = location.Filename(g.src.Location); err != nil {
|
|
return nil, err
|
|
}
|
|
md.FQName = md.Name
|
|
|
|
if md.Size, err = g.files.Filesize(ctx, g.src); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return md, nil
|
|
}
|
|
|
|
// TableMetadata implements driver.Grip.
|
|
func (g *grip) TableMetadata(ctx context.Context, tblName string) (*metadata.Table, error) {
|
|
return g.dbGrip.TableMetadata(ctx, tblName)
|
|
}
|
|
|
|
// Close implements driver.Grip.
|
|
func (g *grip) Close() error {
|
|
g.log.Debug(lgm.CloseDB, lga.Handle, g.src.Handle)
|
|
|
|
return g.dbGrip.Close()
|
|
}
|