github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/catalog/accessor.go (about)

     1  // Copyright 2020 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package catalog
    12  
    13  import (
    14  	"context"
    15  
    16  	"github.com/cockroachdb/cockroach/pkg/keys"
    17  	"github.com/cockroachdb/cockroach/pkg/kv"
    18  	"github.com/cockroachdb/cockroach/pkg/settings/cluster"
    19  	"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
    20  	"github.com/cockroachdb/cockroach/pkg/sql/sqlbase"
    21  )
    22  
    23  // Accessor provides access to sql object descriptors.
    24  type Accessor interface {
    25  	// GetDatabaseDesc looks up a database by name and returns its
    26  	// descriptor. If the database is not found and required is true,
    27  	// an error is returned; otherwise a nil reference is returned.
    28  	GetDatabaseDesc(ctx context.Context, txn *kv.Txn, codec keys.SQLCodec, dbName string, flags tree.DatabaseLookupFlags) (*sqlbase.DatabaseDescriptor, error)
    29  
    30  	// IsValidSchema returns true and the SchemaID if the given schema name is valid for the given database.
    31  	IsValidSchema(ctx context.Context, txn *kv.Txn, codec keys.SQLCodec, dbID sqlbase.ID, scName string) (bool, sqlbase.ID, error)
    32  
    33  	// GetObjectNames returns the list of all objects in the given
    34  	// database and schema.
    35  	// TODO(solon): when separate schemas are supported, this
    36  	// API should be extended to use schema descriptors.
    37  	GetObjectNames(ctx context.Context, txn *kv.Txn, codec keys.SQLCodec, db *sqlbase.DatabaseDescriptor, scName string, flags tree.DatabaseListFlags) (tree.TableNames, error)
    38  
    39  	// GetObjectDesc looks up an object by name and returns both its
    40  	// descriptor and that of its parent database. If the object is not
    41  	// found and flags.required is true, an error is returned, otherwise
    42  	// a nil reference is returned.
    43  	GetObjectDesc(ctx context.Context, txn *kv.Txn, settings *cluster.Settings, codec keys.SQLCodec, db, schema, object string, flags tree.ObjectLookupFlags) (Descriptor, error)
    44  }