Categorygithub.com/DangerosoDavo/go-db
modulepackage
0.0.0-20230311162452-89aa46e132c0
Repository: https://github.com/dangerosodavo/go-db.git
Documentation: pkg.go.dev

# README

go-db

golang package to have easy database creation and usage.

Currently untested, but should work. Use it to store structs and relationships between structs in a mysql database. Has Search and Upsert which queries a database for the given records / related records.

Use the tags GoDBKey:"primary|secondary" to mark specific fields on any given struct to determine the keys/relationships.

This package was made with some assumptions in mind.

Connection pools can be read, write or read/write to support master/slave databases. Just be sure to only add one type of connection pool in each call too AddConnections, multiple AddConnections calls can be made. Requests are blocking but handled as fast as possible and can be used/accessed safely from multiple goroutines. If more queries are requested at the same time than there are active connections then it will wait for a connection to be avaliable and execute the instant one becomes free.

Table names are the pluralized lower case name of the struct if its a basic record upsert, for relationships the table names are the lower case struct names joined with _.

Database support: Mysql

Useful Methods:

  • GoDB.AddConnections Add a connection pool to use, can be read,write or read/write.

  • GoDB.Upsert Used to insert or update the given records in the database.

  • GoDB.Search Allows you to search for instances of the given struct the conditions for the search are defined by a map of columnNames to Where clauses.

  • GoDB.SearchJunctionTable Allows you to search a junction table from the two given structs with a slice of additional fields, the conditions for the search are defined by a map of columnNames to Where clauses.

# Functions

No description provided by the author
NewConnectionPool creates a new connection pool for a given set of DSNs.
No description provided by the author

# 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
No description provided by the author

# Variables

ErrNoConnections is returned when there are no connections available.
Returned when a read operation is attempted on a write only connection.
Returned when a write operation is attempted on a read only connection.

# Structs

No description provided by the author
ConnectionPool is a pool of connections to a database.
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

# Interfaces

No description provided by the author

# Type aliases

No description provided by the author