// Copyright 2021 Dolthub, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package engine import ( "context" "errors" "fmt" "github.com/dolthub/dolt/go/libraries/doltcore/env" "github.com/dolthub/dolt/go/libraries/doltcore/sqle" "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" "github.com/dolthub/dolt/go/libraries/doltcore/table/editor" "github.com/dolthub/dolt/go/libraries/utils/filesys" ) // CollectDBs takes a MultiRepoEnv and creates Database objects from each environment and returns a slice of these // objects. func CollectDBs(ctx context.Context, mrEnv *env.MultiRepoEnv) ([]dsess.SqlDatabase, []filesys.Filesys, error) { var dbs []dsess.SqlDatabase var locations []filesys.Filesys var db dsess.SqlDatabase err := mrEnv.Iter(func(name string, dEnv *env.DoltEnv) (stop bool, err error) { db, err = newDatabase(ctx, name, dEnv) if err != nil { return false, err } dbs = append(dbs, db) locations = append(locations, dEnv.FS) return false, nil }) if err != nil { return nil, nil, err } return dbs, locations, nil } func newDatabase(ctx context.Context, name string, dEnv *env.DoltEnv) (sqle.Database, error) { dbdata := dEnv.DbData(ctx) if !dEnv.Valid() { return sqle.Database{}, fmt.Errorf("failed to load database %q: %w", name, errors.Join(dEnv.CfgLoadErr, dEnv.RSLoadErr, dEnv.DBLoadError)) } return sqle.NewDatabase(ctx, name, dbdata, editor.Options{}) }