modulepackage
3.9.0+incompatible
Repository: https://github.com/datomar-labs-inc/db.git
Documentation: pkg.go.dev
# README
github.com/datomar-labs-inc/db

The github.com/datomar-labs-inc/db
package for Go is a productive data access layer for
Go that provides a common interface to work with different data sources such as
PostgreSQL,
MySQL, SQLite,
MSSQL,
QL and MongoDB.
go get github.com/datomar-labs-inc/db
The tour
Take the tour to see real live examples in your browser.
Live demos
You can run the following example on our playground:
package main
import (
"log"
"github.com/datomar-labs-inc/db/postgresql"
)
var settings = postgresql.ConnectionURL{
Host: "demo.upper.io",
Database: "booktown",
User: "demouser",
Password: "demop4ss",
}
type Book struct {
ID int `db:"id"`
Title string `db:"title"`
AuthorID int `db:"author_id"`
SubjectID int `db:"subject_id"`
}
func main() {
sess, err := postgresql.Open(settings)
if err != nil {
log.Fatalf("db.Open(): %q\n", err)
}
defer sess.Close()
var books []Book
err = sess.Collection("books").Find().All(&books)
if err != nil {
log.Fatalf("Find(): %q\n", err)
}
for i, book := range books {
log.Printf("Book %d: %#v\n", i, book)
}
}
Or you can also run it locally from the _examples
directory:
go run _examples/booktown-books/main.go
2016/08/10 08:42:48 "The Shining" (ID: 7808)
2016/08/10 08:42:48 "Dune" (ID: 4513)
2016/08/10 08:42:48 "2001: A Space Odyssey" (ID: 4267)
2016/08/10 08:42:48 "The Cat in the Hat" (ID: 1608)
2016/08/10 08:42:48 "Bartholomew and the Oobleck" (ID: 1590)
2016/08/10 08:42:48 "Franklin in the Dark" (ID: 25908)
2016/08/10 08:42:48 "Goodnight Moon" (ID: 1501)
2016/08/10 08:42:48 "Little Women" (ID: 190)
2016/08/10 08:42:48 "The Velveteen Rabbit" (ID: 1234)
2016/08/10 08:42:48 "Dynamic Anatomy" (ID: 2038)
2016/08/10 08:42:48 "The Tell-Tale Heart" (ID: 156)
2016/08/10 08:42:48 "Programming Python" (ID: 41473)
2016/08/10 08:42:48 "Learning Python" (ID: 41477)
2016/08/10 08:42:48 "Perl Cookbook" (ID: 41478)
2016/08/10 08:42:48 "Practical PostgreSQL" (ID: 41472)
Documentation for users
This is the source code repository, check out our release notes and see examples and documentation at github.com/datomar-labs-inc/db.
Changelog
See CHANGELOG.md.
License
Licensed under MIT License
Authors and contributors
- José Carlos Nieto <[email protected]>
- Peter Kieltyka <[email protected]>
- Maciej Lisiewski <[email protected]>
- Max Hawkins <[email protected]>
- Paul Xue <[email protected]>
- Kevin Darlington <[email protected]>
- Lars Buitinck <[email protected]>
- icattlecoder <[email protected]>
- Aaron <[email protected]>
- Hiram J. Pérez <[email protected]>
- Julien Schmidt <[email protected]>
- Max Hawkins <[email protected]>
- Piotr "Orange" Zduniak <[email protected]>
- achun <[email protected]>
- rjmcguire <[email protected]>
- wei2912 <[email protected]>
# Packages
No description provided by the author
Package mongo wraps the gopkg.in/mgo.v2 MongoDB driver.
Package mssql wraps the github.com/go-sql-driver/mssql MySQL driver.
Package mysql wraps the github.com/go-sql-driver/mysql MySQL driver.
Package postgresql wraps the github.com/lib/pq PostgreSQL driver.
Package ql wraps the modernc.org/ql/driver QL driver.
Package sqlite wraps the github.com/lib/sqlite SQLite driver.
# Functions
After indicates whether the reference is after the given time.
And joins conditions under logical conjunction.
Before indicates whether the reference is before the given time.
Between indicates whether the reference is contained between the two given values.
Eq indicates whether the constraint is equal to the given argument.
Func represents a database function and satisfies the db.Function interface.
Gt indicates whether the constraint is greater than the given argument.
Gte indicates whether the reference is greater than or equal to the given argument.
In indicates whether the argument is part of the reference.
Is indicates whether the reference is nil, true or false.
IsNot indicates whether the reference is not nil, true nor false.
IsNotNull indicates whether the reference is a NULL value.
IsNull indicates whether the reference is a NULL value.
Like indicates whether the reference matches the wildcard value.
Lt indicates whether the constraint is less than the given argument.
Lte indicates whether the reference is less than or equal to the given argument.
NewConstraint creates a constraint.
NewSettings returns a new settings value prefilled with the current default settings.
NotBetween indicates whether the reference is not contained between the two given values.
NotEq indicates whether the constraint is not equal to the given argument.
NotIn indicates whether the argument is not part of the reference.
NotLike indicates whether the reference does not match the wildcard value.
NotRegExp indicates whether the reference does not match the regexp pattern.
OnOrAfter indicater whether the reference is after or equal to the given time value.
OnOrBefore indicates whether the reference is before or equal to the given time value.
Op represents a custom comparison operator against the reference.
Open attempts to open a database.
Or joins conditions under logical disjunction.
Raw marks chunks of data as protected, so they pass directly to the query without any filtering.
RegExp indicates whether the reference matches the regexp pattern.
RegisterAdapter registers a generic Database adapter.
# Constants
Comparison operators.
Comparison operators.
Comparison operators.
Comparison operators.
Comparison operators.
Comparison operators.
Comparison operators.
Comparison operators.
Comparison operators.
Comparison operators.
Comparison operators.
Comparison operators.
Comparison operators.
Comparison operators.
Comparison operators.
Comparison operators.
Comparison operators.
Comparison operators.
Comparison operators.
Comparison operators.
Comparison operators.
EnvEnableDebug can be used by adapters to determine if the user has enabled debugging.
Compound operators.
Compound operators.
Compound operators.
# Variables
DefaultSettings provides default global configuration settings for database sessions.
Error messages.
Error messages.
Error messages.
Error messages.
Error messages.
Error messages.
Error messages.
Error messages.
Error messages.
Error messages.
Error messages.
Error messages.
Error messages.
Error messages.
Error messages.
Error messages.
Error messages.
Error messages.
Error messages.
Error messages.
Error messages.
Error messages.
# Structs
AdapterFuncMap defines functions that need to be implemented by adapters.
Intersection represents a compound joined by AND.
QueryStatus represents the status of a query after being executed.
Union represents a compound joined by OR.
# Interfaces
Collection is an interface that defines methods useful for handling tables.
Comparison defines methods for representing comparison operators in a portable way across databases.
Compound represents an statement that has one or many sentences joined by by an operator like "AND" or "OR".
ConnectionURL represents a connection string.
Constraint interface represents a single condition, like "a = 1".
Constraints interface represents an array or constraints, like "a = 1, b = 2, c = 3".
Database is an interface that defines methods that must be satisfied by all database adapters.
Function interface defines methods for representing database functions.
Logger represents a logging collector.
Marshaler is the interface implemented by struct fields that can transform themselves into values that can be stored on a database.
RawValue interface represents values that can bypass SQL filters.
Result is an interface that defines methods which are useful for working with result sets.
Settings defines methods to get or set configuration values.
Tx has methods for transactions that can be either committed or rolled back.
Unmarshaler is the interface implemented by struct fields that can transform themselves from stored database values into Go values.
# Type aliases
ComparisonOperator is a type we use to label comparison operators.
CompoundOperator represents the operation on a compound statement.
Cond is a map that defines conditions for a query and satisfies the Constraints and Compound interfaces.