# README
Bob: Go SQL Access Toolkit
Links
About
Bob is a set of Go packages and tools to work with SQL databases.
Bob's philosophy centres around the following:
- Correctness: Things should work correctly. Follow specifications as closely as possible.
- Convenience (not magic): Bob provides convenient ways to perform actions, it does not add unexplainable magic, or needless abstraction.
- Cooperation: Bob should work well with other tools and packages as much as possible, especially the standard library.
Bob can be progressively adopted from raw SQL query strings, to fully typed queries with models and factories generated for your database.
Components of Bob
Bob consists of several components that build on each other for the full experience.
- Query Builder
- SQL Executor for convenient scanning of results
- Models for convenient database queries
- Code generation of Models and Factories from your database schema
Check out the documentation for more information.
Support
Queries | Models | ORM Gen | Factory Gen | |
---|---|---|---|---|
Postgres | ✅ | ✅ | ✅ | ✅ |
MySQL/MariaDB | ✅ | ✅ | ✅ | ✅ |
SQLite | ✅ | ✅ | ✅ | ✅ |
Comparisons
Contributing
Thanks to all the people who have contributed to Bob!
# Packages
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
# Functions
No description provided by the author
Allx takes 2 type parameters.
No description provided by the author
Convinient function to build query from start.
Convinient function to build query from a point.
No description provided by the author
No description provided by the author
Cursor returns a cursor that works similar to *sql.Rows.
Debug wraps an [Executor] and prints the queries and args to os.Stdout.
DebugToPrinter wraps an existing [Executor] and writes all queries and args to the given [DebugPrinter] if w is nil, it fallsback to writing to [os.Stdout].
DebugToWriter wraps an existing [Executor] and writes all queries and args to the given [io.Writer] if w is nil, it fallsback to [os.Stdout].
No description provided by the author
No description provided by the author
ExpressIf expands an express if the condition evaluates to true it can also add a prefix and suffix.
ExpressSlice is used to express a slice of expressions along with a prefix and suffix.
InTx returns a new MappedStmt that will be executed in the given transaction.
MustBuild builds a query and panics on error useful for initializing queries that need to be reused.
No description provided by the author
Named args should ONLY be used to prepare statements.
NamedGroup is like Named, but wraps in parentheses.
New wraps an stdInterface to make it comply with Queryer It also includes a number of other methods that are often used with *sql.DB, *sql.Tx and *sql.Conn.
NewConn wraps an [*sql.Conn] and returns a type that implements [Queryer] This is useful when an existing *sql.Conn is used in other places in the codebase.
NewDB wraps an [*sql.DB] and returns a type that implements [Queryer] but still retains the expected methods used by *sql.DB This is useful when an existing *sql.DB is used in other places in the codebase.
NewQueryer wraps an [stdscan.Queryer] and makes it a [scan.Queryer].
NewTx wraps an [*sql.Tx] and returns a type that implements [Queryer] but still retains the expected methods used by *sql.Tx This is useful when an existing *sql.Tx is used in other places in the codebase.
No description provided by the author
Open works just like [sql.Open], but converts the returned [*sql.DB] to [DB].
OpenDB works just like [sql.OpenDB], but converts the returned [*sql.DB] to [DB].
Prepare prepares a query using the [Preparer] and returns a [NamedStmt].
No description provided by the author
No description provided by the author
SkipHooks modifies a context to prevent hooks from running for any query it encounters.
SkipModelHooks modifies a context to prevent hooks from running on models.
SkipQueryHooks modifies a context to prevent hooks from running on querys.
ToMods converts a slice of a type that implements Mod[T] to Mods[T] this is useful since a slice of structs that implement Mod[T] cannot be directly used as a slice of Mod[T].
# Constants
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
# Variables
nolint:gochecknoglobals.
No description provided by the author
nolint:gochecknoglobals.
# Structs
BaseQuery wraps common functionality such as cloning, applying new mods and the actual query interface implementation.
No description provided by the author
Conn is similar to *sql.Conn but implements [Queryer].
No description provided by the author
DB is similar to *sql.DB but implement [Queryer].
No description provided by the author
Hooks is a set of hooks that can be called all at once.
Load is an embeddable struct that enables Preloading and AfterLoading.
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
Stmt is similar to *sql.Stmt but implements [Queryer] instead of taking a list of args, it takes a struct to bind to the query.
Tx is similar to *sql.Tx but implements [Queryer].
No description provided by the author
# Interfaces
ContextualMods are special types of mods that require a context.
DebugPrinter is used to print queries and arguments.
Dialect provides expressions with methods to write parts of the query.
DialectWithNamed is a [Dialect] with the additional ability to WriteNamedArgs.
No description provided by the author
Expression represents a section of a query.
No description provided by the author
No description provided by the author
Loadable is an object that has loaders if a query implements this interface, the loaders are called after executing the query.
Loader is an object that is called after the main query is performed when called from [Exec], retrieved is nil when called from [One], retrieved is the retrieved object when called from [All], retrieved is a slice retrieved objects this is used for loading relationships.
No description provided by the author
Mod is a generic interface for modifying a query It is the building block for creating queries.
No description provided by the author
No description provided by the author
No description provided by the author
StdInterface is an interface that *sql.DB, *sql.Tx and *sql.Conn satisfy.
# Type aliases
No description provided by the author
No description provided by the author
Hook is a function that can be called during lifecycle of an object the context can be modified and returned The caller is expected to use the returned context for subsequent processing.
Loader builds a query mod that makes an extra query after the object is retrieved it can be used to prevent N+1 queries by loading relationships in batches.
No description provided by the author
No description provided by the author
No description provided by the author