package
0.18.0
Repository: https://github.com/hashicorp/boundary.git
Documentation: pkg.go.dev

# README

db package

Usage

Just some high-level usage highlights to get you started. Read the godocs for a complete list of capabilities and their documentation.

    dialect = postgres.New(postgres.Config{
			DSN: connectionUrl},
		)
    conn, _ := gorm.Open(dialect, &gorm.Config{})
    
    // Db implements both the Reader and Writer interfaces
    rw := Db{Tx: conn}
    
    // There are writer methods like: Create, Update and Delete
    // that will write Gorm struct to the db.  These writer methods
    // all support options for writing Oplog entries for the 
    // caller: WithOplog(yourWrapper, yourMetadata)
    // the caller is responsible for the transaction life cycle of the writer
    // and if an error is returned the caller must decide what to do with 
    // the transaction, which is almost always a rollback for the caller.
    err = rw.Create(context.Background(), user)
   
    // There are reader methods like: LookupByPublicId,  
    // LookupByName, SearchBy, LookupBy, etc
    // which will lookup resources for you and scan them into your Gorm struct
    err = rw.LookupByPublicId(context.Background(), foundUser)

    // There's reader ScanRows that facilitates scanning rows from 
    // a query into your Gorm struct
    where := "select * from test_users where name in ($1, $2)"
    rows, err := rw.Query(context.Background(), where, []interface{}{"alice", "bob"})
	defer rows.Close()
	for rows.Next() {
        user := db_test.NewTestUser()
        // scan the row into your Gorm struct
		if err := rw.ScanRows(rows, &user); err != nil {
            return err
        }
        // Do something with the Gorm user struct
    }
    if err := rows.Err(); err != nil {
        // do something with the err
    }

    // DoTx is a writer function that wraps a TxHandler 
    // in a retryable transaction.  You simply implement a
    // TxHandler that does your writes and hand the handler
    // to DoTx, which will wrap the writes in a retryable 
    // transaction with the retry attempts and backoff
    // strategy you specify via options.
    _, err = w.DoTx(
        context.Background(),
        10,           // ten retries
        ExpBackoff{}, // exponential backoff
        func(w Writer) error {
            // the TxHandler updates the user's friendly name
            return w.Update(context.Background(), user, []string{"FriendlyName"},
                // write oplogs for this update
                WithOplog(
                    InitTestWrapper(t),
                    oplog.Metadata{
                        "key-only":   nil,
                        "deployment": []string{"amex"},
                        "project":    []string{"central-info-systems", "local-info-systems"},
                    },
                ),
            )
        })


# Packages

Package dbassert provides a set of assertions for testing the boundary database applications.
No description provided by the author
Package db_test provides some helper funcs for testing db integrations.
Package sanitize contains a set of functions that sanitizes input received from external systems before being persisted in the database.
Package schema is used to apply sql migrations to modify the state of a database instance.
Package sentinel allows for the use of Unicode non-characters to distinguish between Boundary defined sentinels and values provided by external systems.
No description provided by the author

# Functions

AssertPublicId is a test helper that asserts that the provided id is in the format of a public id.
Expr creates an expression value (ExprValue) which can be used when setting column values for database operations.
GetOpts - iterate the inbound Options and return a struct.
No description provided by the author
No description provided by the author
No description provided by the author
NewOplogMsg provides an option to ask for a new in-memory oplog message.
NewOplogMsgs provides an option to ask for multiple new in-memory oplog messages.
No description provided by the author
NewPublicId creates a new public id with the prefix.
Open a database connection which is long-lived.
SetColumns defines a list of column (names) to update using the set of proposed insert columns during an on conflict update.
SetColumnValues defines a map from column names to values.
No description provided by the author
TestCreateTables will create the test tables for the db pkg.
TestDeleteWhere allows you to easily delete resources for testing purposes including all the current resources.
TestOplogWrapper initializes a DB wrapper for testing.
setup the tests (initialize the database one-time and initialized testDatabaseURL).
TestSetupWithMock will return a test DB and an associated Sqlmock which can be used to mock out the db responses.
TestVerifyOplog will verify that there is an oplog entry that matches the provided resourceId.
TestWrapper initializes an AEAD wrapping.Wrapper for testing.
WithConnMaxIdleTimeDuration specifies an optional connection max idle time for the database.
WithCreateNotBefore provides an option to specify that the create time is not before (nbf) N seconds.
WithDebug specifies the given operation should invoke debug mode in Gorm.
WithFieldMaskPaths provides an option to provide field mask paths.
WithGormFormatter specifies an optional hclog to use for gorm's log formmater.
WithLimit provides an option to provide a limit.
WithLookup enables a lookup.
WithMaxIdleConnections specifies an optional max idle connections for the database.
WithMaxOpenConnections specifies an optional max open connections for the database.
WithNullPaths provides an option to provide null paths.
WithOnConflict specifies an optional on conflict criteria which specify alternative actions to take when an insert results in a unique constraint or exclusion constraint error.
WithOperation provides an option to specify the operation type.
WithOplog provides an option to write an oplog entry.
WithOrder provides an option to provide an order when searching and looking up.
WithPrngValues provides an option to provide values to seed an PRNG when generating IDs.
WithResourcePrivateId provides a way to specify that the resource lookup action uses `resource-private-id` tag instead of the default `resource-public-id` tag.
WithReturnRowsAffected specifies an option for returning the rows affected.
WithSkipVetForWrite provides an option to allow skipping vet checks to allow testing lower-level SQL triggers and constraints.
WithTemplate provides a way to specify the source database template for creating a database.
WithTestDatabaseUrl provides a way to specify an existing database for tests.
WithTestLogLevel provides a way to specify a test log level for the underlying database package (if applicable).
WithVersion provides an option version number for update operations.
WithWhere provides an option to provide a where clause with arguments for an operation.

# Constants

AscendingOrderBy would designate ordering the column in ascending order.
No description provided by the author
No description provided by the author
DefaultLimit is the default for results for boundary.
See WithTestLogLevel(...) test only option.
No description provided by the author
No description provided by the author
DescendingOrderBy would designate ordering the column in decending order.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
UnknownOrderBy would designate an unknown ordering of the column, which is the standard ordering for any select without an order by clause.
No description provided by the author
No description provided by the author

# Variables

No description provided by the author

# Structs

ColumnValue defines a column and it's assigned value for a database operation.
No description provided by the author
Db uses a gorm DB connection for read/write.
DB is a wrapper around the ORM.
No description provided by the author
ExprValue encapsulates an expression value for a column assignment.
OnConflict specifies how to handle alternative actions to take when an insert results in a unique constraint or exclusion constraint error.
Options - how Options are represented.
RetryInfo provides information on the retries of a transaction.

# Interfaces

No description provided by the author
Reader interface defines lookups/searching for resources.
ResourcePrivateIder defines an interface that LookupById() can use to get the resource's private id.
ResourcePublicIder defines an interface that LookupByPublicId() can use to get the resource's public id.
VetForWriter provides an interface that Create and Update can use to vet the resource before before writing it to the db.
Writer interface defines create, update and retryable transaction handlers.

# Type aliases

Columns defines a set of column names.
Constraint defines database constraint name.
No description provided by the author
DoNothing defines an "on conflict" action of doing nothing.
Option - how Options are passed as arguments.
No description provided by the author
OrderBy defines an enum type for declaring a column's order by criteria.
TestLogLevel defines a test log level for the underlying db package (if applicable).
TestOption - how Options are passed as arguments.
TxHandler defines a handler for a func that writes a transaction for use with DoTx.
UpdateAll defines an "on conflict" action of updating all columns using the proposed insert column values.