mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-11 02:59:34 -06:00
dolt session methods error when no config -- for DoltHub (#2341)
This commit is contained in:
committed by
GitHub
parent
9db9a0f9dc
commit
5fe094b8ed
@@ -15,6 +15,7 @@
|
||||
package dsess
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"sync"
|
||||
@@ -26,6 +27,8 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/utils/config"
|
||||
)
|
||||
|
||||
var ErrSessionNotPeristable = errors.New("session is not persistable")
|
||||
|
||||
type DoltSession struct {
|
||||
*Session
|
||||
globalsConf config.ReadWriteConfig
|
||||
@@ -55,6 +58,10 @@ func NewDoltSession(ctx *sql.Context, sqlSess *sql.BaseSession, pro RevisionData
|
||||
|
||||
// PersistGlobal implements sql.PersistableSession
|
||||
func (s *DoltSession) PersistGlobal(sysVarName string, value interface{}) error {
|
||||
if s.globalsConf == nil {
|
||||
return ErrSessionNotPeristable
|
||||
}
|
||||
|
||||
sysVar, _, err := validatePersistableSysVar(sysVarName)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -67,6 +74,10 @@ func (s *DoltSession) PersistGlobal(sysVarName string, value interface{}) error
|
||||
|
||||
// RemovePersistedGlobal implements sql.PersistableSession
|
||||
func (s *DoltSession) RemovePersistedGlobal(sysVarName string) error {
|
||||
if s.globalsConf == nil {
|
||||
return ErrSessionNotPeristable
|
||||
}
|
||||
|
||||
sysVar, _, err := validatePersistableSysVar(sysVarName)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -79,6 +90,10 @@ func (s *DoltSession) RemovePersistedGlobal(sysVarName string) error {
|
||||
|
||||
// RemoveAllPersistedGlobals implements sql.PersistableSession
|
||||
func (s *DoltSession) RemoveAllPersistedGlobals() error {
|
||||
if s.globalsConf == nil {
|
||||
return ErrSessionNotPeristable
|
||||
}
|
||||
|
||||
allVars := make([]string, s.globalsConf.Size())
|
||||
i := 0
|
||||
s.globalsConf.Iter(func(k, v string) bool {
|
||||
@@ -94,11 +109,19 @@ func (s *DoltSession) RemoveAllPersistedGlobals() error {
|
||||
|
||||
// RemoveAllPersistedGlobals implements sql.PersistableSession
|
||||
func (s *DoltSession) GetPersistedValue(k string) (interface{}, error) {
|
||||
if s.globalsConf == nil {
|
||||
return nil, ErrSessionNotPeristable
|
||||
}
|
||||
|
||||
return getPersistedValue(s.globalsConf, k)
|
||||
}
|
||||
|
||||
// SystemVariablesInConfig returns a list of System Variables associated with the session
|
||||
func (s *DoltSession) SystemVariablesInConfig() ([]sql.SystemVariable, error) {
|
||||
if s.globalsConf == nil {
|
||||
return nil, ErrSessionNotPeristable
|
||||
}
|
||||
|
||||
return SystemVariablesInConfig(s.globalsConf)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,14 +17,12 @@ package dsess
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/filesys"
|
||||
)
|
||||
|
||||
// SessionStateAdapter is an adapter for env.RepoStateReader in SQL contexts, getting information about the repo state
|
||||
@@ -156,11 +154,3 @@ func (s SessionStateAdapter) RemoveBackup(ctx context.Context, name string) erro
|
||||
func (s SessionStateAdapter) TempTableFilesDir() string {
|
||||
return s.session.GetDbStates()[s.dbName].tmpTablesDir
|
||||
}
|
||||
|
||||
func mustAbs(path ...string) string {
|
||||
absPath, err := filesys.LocalFS.Abs(filepath.Join(path...))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return absPath
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user