Documentation
¶
Overview ¶
Table provides a standardization of working with database tables.
The example below shows storing passwords in a database.
Example:
At first you will need to implement the concrete implementation of the Table interface. In a package containing the type to store (in this case passwords):
import "github.com/Polshkrev/gopolutils/table"
var _ table.Table[password.Password] = (*Table)(nil)
const (
TableName string = "passwords"
)
var (
fieldString = table.GetFields( // The variadic table column names )
)
type Table struct {
// Implementation of the table...
}
// Methods for the table...
Setup for a database:
import(
"github.com/Polshkrev/gopolutils/fayl"
"github.com/Polshkrev/gopolutils/table"
"github.com/Polshkrev/gopolutils/table/connect"
)
var (
path *fayl.Path = fayl.PathFrom("path/to/database.db")
)
func main() {
var connection *sql.DB = gopolutils.Must(connect.Connect(driver, path))
var database table.Table[password.Password] = password.NewTable(connection)
database.Create(password.TableName)
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Accessor ¶
type Accessor[Type any] interface { // Obtain the item stored in a database at the given id. // Returns the item stored in a database at the given id. // If the item can not be obtained, a [gopolutils.ValueError] is returned with a nil data pointer. Get(id gopolutils.Size) (*Type, *gopolutils.Exception) // Obtain all the items stored in a database. // Returns a [collections.View] of all the items stored in a database. // If the items can not be obtained, an [gopolutils.IOError] is returned with a nil data pointer. GetAll() (collections.View[*Type], *gopolutils.Exception) }
Representation of a database accessor.
type Closer ¶
type Closer interface {
// Close a database.
// If a database can not close, an [gopolutils.IOError] is returned.
Close() *gopolutils.Exception
}
Representation of a database closer.
type Creator ¶
type Creator interface {
// Create a database with a given name.
// If the database can not be created, an [gopolutils.IOError] is returned.
Create(name string) *gopolutils.Exception
}
Representation of a database creator.
type Driver ¶
type Driver gopolutils.StringEnum
Representation of a database driver.
const (
Sqlite Driver = "sqlite3" // An sqlite driver.
)
type Dropper ¶
type Dropper interface {
// Drop a database with a given name.
// If the database can not be dropped, an [gopolutils.IOError] is returned.
Drop(name string) *gopolutils.Exception
}
Representation of a database dropper.
type Field ¶
type Field gopolutils.StringEnum
Representation of a database field.
const (
Id Field = "id" // Default id field.
)
type Getter ¶
type Getter interface {
// Obtain the name of the database.
Name() string
// Obtain a handle to the database.
Connection() *sql.DB
}
Representation of a database getter.
type Inserter ¶
type Inserter[Type any] interface { // Insert a given record into the database. // If the given record can not be inserted, an [gopolutils.IOError] is returned. Insert(record Type) *gopolutils.Exception // Insert a [collections.View] of records into the database. // If the given records can not be inserted, an [gopolutils.IOError] is returned. InsertMany(records collections.View[Type]) *gopolutils.Exception }
Representation of a database inserter.
type Remover ¶
type Remover[Type any] interface { // Remove a given item from a database. // If the given item can not be removed, an [gopolutils.IOError] is returned. Remove(item Type) *gopolutils.Exception }
Representation of a database remover.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.