Skip to content

Commit

Permalink
feat(database/offline): implement offline store method Snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
jinghancc committed Dec 30, 2021
1 parent eaf4448 commit d3c78be
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/database/offline/bigquery/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"

"github.com/oom-ai/oomstore/internal/database/offline/sqlutil"

"github.com/spf13/cast"
"google.golang.org/api/iterator"

Expand Down Expand Up @@ -68,3 +70,12 @@ func (db *DB) TableSchema(ctx context.Context, tableName string) (*types.DataTab

return &schema, nil
}

func (db *DB) Snapshot(ctx context.Context, opt offline.SnapshotOpt) error {
dbOpt := dbutil.DBOpt{
Backend: types.BackendBigQuery,
BigQueryDB: db.Client,
DatasetID: &db.datasetID,
}
return sqlutil.Snapshot(ctx, dbOpt, opt)
}
8 changes: 8 additions & 0 deletions internal/database/offline/mysql/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,11 @@ func (db *DB) Join(ctx context.Context, opt offline.JoinOpt) (*types.JoinResult,
func (db *DB) TableSchema(ctx context.Context, tableName string) (*types.DataTableSchema, error) {
return nil, fmt.Errorf("not implemented")
}

func (db *DB) Snapshot(ctx context.Context, opt offline.SnapshotOpt) error {
dbOpt := dbutil.DBOpt{
Backend: types.BackendMySQL,
SqlxDB: db.DB,
}
return sqlutil.Snapshot(ctx, dbOpt, opt)
}
8 changes: 8 additions & 0 deletions internal/database/offline/postgres/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,11 @@ func (db *DB) TableSchema(ctx context.Context, tableName string) (*types.DataTab
}
return sqlutil.SqlxTableSchema(ctx, db, BackendType, rows)
}

func (db *DB) Snapshot(ctx context.Context, opt offline.SnapshotOpt) error {
dbOpt := dbutil.DBOpt{
Backend: types.BackendPostgres,
SqlxDB: db.DB,
}
return sqlutil.Snapshot(ctx, dbOpt, opt)
}
8 changes: 8 additions & 0 deletions internal/database/offline/redshift/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,11 @@ func (db *DB) TableSchema(ctx context.Context, tableName string) (*types.DataTab
}
return sqlutil.SqlxTableSchema(ctx, db, BackendType, rows)
}

func (db *DB) Snapshot(ctx context.Context, opt offline.SnapshotOpt) error {
dbOpt := dbutil.DBOpt{
Backend: types.BackendRedshift,
SqlxDB: db.DB,
}
return sqlutil.Snapshot(ctx, dbOpt, opt)
}
8 changes: 8 additions & 0 deletions internal/database/offline/snowflake/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,11 @@ func (db *DB) Join(ctx context.Context, opt offline.JoinOpt) (*types.JoinResult,
func (db *DB) TableSchema(ctx context.Context, tableName string) (*types.DataTableSchema, error) {
return nil, fmt.Errorf("not implemented")
}

func (db *DB) Snapshot(ctx context.Context, opt offline.SnapshotOpt) error {
dbOpt := dbutil.DBOpt{
Backend: types.BackendSnowflake,
SqlxDB: db.DB,
}
return sqlutil.Snapshot(ctx, dbOpt, opt)
}
8 changes: 8 additions & 0 deletions internal/database/offline/sqlite/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@ func (db *DB) Join(ctx context.Context, opt offline.JoinOpt) (*types.JoinResult,
func (db *DB) TableSchema(ctx context.Context, tableName string) (*types.DataTableSchema, error) {
return nil, fmt.Errorf("not implemented")
}

func (db *DB) Snapshot(ctx context.Context, opt offline.SnapshotOpt) error {
dbOpt := dbutil.DBOpt{
Backend: types.BackendSQLite,
SqlxDB: db.DB,
}
return sqlutil.Snapshot(ctx, dbOpt, opt)
}
1 change: 1 addition & 0 deletions internal/database/offline/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Store interface {
Import(ctx context.Context, opt ImportOpt) (int64, error)

TableSchema(ctx context.Context, tableName string) (*types.DataTableSchema, error)
Snapshot(ctx context.Context, opt SnapshotOpt) error

Ping(ctx context.Context) error
io.Closer
Expand Down
7 changes: 7 additions & 0 deletions internal/database/offline/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,10 @@ type CSVSource struct {
Reader *bufio.Reader
Delimiter string
}

type SnapshotOpt struct {
Group *types.Group
Features types.FeatureList
RevisionID int
PrevRevisionID int
}

0 comments on commit d3c78be

Please sign in to comment.