Documentation
¶
Overview ¶
Package storage provides the functions that interacts with Spanner to fetch the data
Index ¶
- Constants
- func EvaluateConditionalExpression(ctx context.Context, t *spanner.ReadWriteTransaction, table string, ...) (bool, error)
- func InitSpannerDriver() *spanner.Client
- func InitializeDriver(ctx context.Context) error
- func SetStorageInstance(s *Storage)
- type Storage
- func (s Storage) BuildCommitOptions() spanner.CommitOptions
- func (s Storage) Close()
- func (s Storage) ExecuteSpannerQuery(ctx context.Context, table string, cols []string, isCountQuery bool, ...) ([]map[string]interface{}, error)
- func (s *Storage) GetSpannerClient() (*spanner.Client, error)
- func (s *Storage) InsertUpdateOrDeleteStatement(ctx context.Context, query *translator.DeleteUpdateQueryMap) (map[string]interface{}, error)
- func (s Storage) SpannerAdd(ctx context.Context, table string, m map[string]interface{}, eval *models.Eval, ...) (map[string]interface{}, error)
- func (s Storage) SpannerBatchDelete(ctx context.Context, table string, keys []map[string]interface{}) error
- func (s Storage) SpannerBatchGet(ctx context.Context, tableName string, pKeys, sKeys []interface{}, ...) ([]map[string]interface{}, error)
- func (s Storage) SpannerBatchPut(ctx context.Context, table string, m []map[string]interface{}, ...) error
- func (s Storage) SpannerDel(ctx context.Context, table string, m map[string]interface{}, eval *models.Eval, ...) error
- func (s Storage) SpannerDelete(ctx context.Context, table string, m map[string]interface{}, eval *models.Eval, ...) error
- func (s Storage) SpannerGet(ctx context.Context, tableName string, pKeys, sKeys interface{}, ...) (map[string]interface{}, map[string]interface{}, error)
- func (s Storage) SpannerPut(ctx context.Context, table string, m map[string]interface{}, eval *models.Eval, ...) (map[string]interface{}, error)
- func (s Storage) SpannerRemove(ctx context.Context, table string, m map[string]interface{}, eval *models.Eval, ...) error
- func (s Storage) SpannerTransactGetItems(ctx context.Context, tableProjectionCols map[string][]string, ...) ([]map[string]interface{}, error)
- func (s Storage) SpannerTransactWritePut(ctx context.Context, table string, m map[string]interface{}, eval *models.Eval, ...) (map[string]interface{}, *spanner.Mutation, error)
- func (s Storage) TransactWriteSpannerAdd(ctx context.Context, table string, m map[string]interface{}, eval *models.Eval, ...) (map[string]interface{}, *spanner.Mutation, error)
- func (s Storage) TransactWriteSpannerDel(ctx context.Context, table string, m map[string]interface{}, eval *models.Eval, ...) (*spanner.Mutation, error)
- func (s Storage) TransactWriteSpannerDelete(ctx context.Context, table string, m map[string]interface{}, eval *models.Eval, ...) (*spanner.Mutation, error)
- func (s Storage) TransactWriteSpannerRemove(ctx context.Context, table string, m map[string]interface{}, eval *models.Eval, ...) (*spanner.Mutation, error)
Constants ¶
const ( SpannerBatchGetAnnotation = "Calling SpannerBatchGet Method" SpannerGetAnnotation = "Calling SpannerGet Method" ExecuteSpannerQueryAnnotation = "Calling ExecuteSpannerQuery Method" SpannerPutAnnotation = "Calling SpannerPut Method" SpannerDeleteAnnotation = "Calling SpannerDelete Method" SpannerBatchDeleteAnnotation = "Calling SpannerBatchDelete Method" SpannerAddAnnotation = "Calling SpannerAdd Method" SpannerDelAnnotation = "Calling SpannerDel Method" SpannerRemoveAnnotation = "Calling SpannerRemove Method" SpannerBatchPutAnnotation = "Calling SpannerBatchPut Method" )
Variables ¶
This section is empty.
Functions ¶
func InitSpannerDriver ¶
func InitializeDriver ¶
func SetStorageInstance ¶
func SetStorageInstance(s *Storage)
Types ¶
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage object for intracting with storage package
func GetStorageInstance ¶
func GetStorageInstance() *Storage
GetStorageInstance - return storage instance to call db functionalities
func (Storage) BuildCommitOptions ¶
func (s Storage) BuildCommitOptions() spanner.CommitOptions
BuildCommitOptions returns the commit options for Spanner transactions.
func (Storage) Close ¶
func (s Storage) Close()
Close - This gracefully returns the session pool objects, when driver gets exit signal
func (Storage) ExecuteSpannerQuery ¶
func (s Storage) ExecuteSpannerQuery(ctx context.Context, table string, cols []string, isCountQuery bool, stmt spanner.Statement) ([]map[string]interface{}, error)
ExecuteSpannerQuery - this will execute query on spanner database
func (*Storage) InsertUpdateOrDeleteStatement ¶
func (s *Storage) InsertUpdateOrDeleteStatement(ctx context.Context, query *translator.DeleteUpdateQueryMap) (map[string]interface{}, error)
InsertUpdateOrDeleteStatement performs insert, update, or delete operations on a Spanner database table based on the provided query map.
Parameters: - ctx: The context for managing request-scoped values, cancelations, and timeouts. - query: A pointer to DeleteUpdateQueryMap, which holds the table name and query details for execution.
Returns: - map[string]interface{}: A map that could potentially hold results for further processing (currently returns nil). - error: An error object, if any error occurs during the transaction execution.
func (Storage) SpannerAdd ¶
func (s Storage) SpannerAdd(ctx context.Context, table string, m map[string]interface{}, eval *models.Eval, expr *models.UpdateExpressionCondition) (map[string]interface{}, error)
SpannerAdd - Spanner Add functionality like update attribute
func (Storage) SpannerBatchDelete ¶
func (s Storage) SpannerBatchDelete(ctx context.Context, table string, keys []map[string]interface{}) error
SpannerBatchDelete - this delete the data in batch
func (Storage) SpannerBatchGet ¶
func (s Storage) SpannerBatchGet(ctx context.Context, tableName string, pKeys, sKeys []interface{}, projectionCols []string) ([]map[string]interface{}, error)
SpannerBatchGet - fetch all rows
func (Storage) SpannerBatchPut ¶
func (s Storage) SpannerBatchPut(ctx context.Context, table string, m []map[string]interface{}, spannerRow []map[string]interface{}) error
SpannerBatchPut - this insert or update data in batch
func (Storage) SpannerDel ¶
func (Storage) SpannerDelete ¶
func (s Storage) SpannerDelete(ctx context.Context, table string, m map[string]interface{}, eval *models.Eval, expr *models.UpdateExpressionCondition) error
SpannerDelete - this will delete the data
func (Storage) SpannerGet ¶
func (s Storage) SpannerGet(ctx context.Context, tableName string, pKeys, sKeys interface{}, projectionCols []string) (map[string]interface{}, map[string]interface{}, error)
SpannerGet - get with spanner
func (Storage) SpannerPut ¶
func (s Storage) SpannerPut(ctx context.Context, table string, m map[string]interface{}, eval *models.Eval, expr *models.UpdateExpressionCondition, spannerRow map[string]interface{}) (map[string]interface{}, error)
SpannerPut - Spanner put insert a single object
func (Storage) SpannerRemove ¶
func (s Storage) SpannerRemove(ctx context.Context, table string, m map[string]interface{}, eval *models.Eval, expr *models.UpdateExpressionCondition, colsToRemove []string, oldRes map[string]interface{}) error
SpannerRemove - Spanner Remove functionality like update attribute
func (Storage) SpannerTransactGetItems ¶
func (s Storage) SpannerTransactGetItems(ctx context.Context, tableProjectionCols map[string][]string, pValues map[string]interface{}, sValues map[string]interface{}) ([]map[string]interface{}, error)
SpannerTransactGetItems is a utility function to fetch data for a single TransactGetItems operation. It takes a context, a table name, a map of projection columns, a map of primary keys, and a map of secondary keys. It returns a slice of maps and an error. The function first gets a Spanner client and then performs a transaction read operation. It then iterates over the results and parses the Spanner rows into DynamoDB-style rows. Finally, it returns the parsed rows.
func (Storage) SpannerTransactWritePut ¶
func (s Storage) SpannerTransactWritePut(ctx context.Context, table string, m map[string]interface{}, eval *models.Eval, expr *models.UpdateExpressionCondition, txn *spanner.ReadWriteTransaction, oldRes map[string]interface{}) (map[string]interface{}, *spanner.Mutation, error)
SpannerTransactWritePut performs a transactional write operation in Spanner. It checks for conditional expressions and updates the database accordingly.
Args:
ctx: The context for managing request deadlines and cancellations. table: The name of the table to update. m: The map containing the data to be inserted or updated. eval: The evaluation criteria for processing conditional expressions. expr: The UpdateExpressionCondition to be checked before writing. txn: The Spanner ReadWriteTransaction.
Returns:
A map of updated data, a Spanner mutation, and an error if any occurs.
func (Storage) TransactWriteSpannerAdd ¶
func (Storage) TransactWriteSpannerDel ¶
func (Storage) TransactWriteSpannerDelete ¶
func (Storage) TransactWriteSpannerRemove ¶
func (s Storage) TransactWriteSpannerRemove(ctx context.Context, table string, m map[string]interface{}, eval *models.Eval, expr *models.UpdateExpressionCondition, colsToRemove []string, txn *spanner.ReadWriteTransaction) (*spanner.Mutation, error)
TransactWriteSpannerRemove - Spanner Remove functionality like update attribute inside a transaction
This is used in the context of a transaction, and it will remove the given columns from the given table. The condition expression in the eval and expr parameters will be evaluated and if it fails, this will return an error.
The colsToRemove parameter should contain the names of the columns to be removed.