table

package
v1.39.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 4 Imported by: 0

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

func GetFields

func GetFields(fields ...Field) string

Represent a variadic amount of [Field]s as a slice of string. Represents a variadic amount of [Field]s as a slice of string.

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.
)

func (Field) String

func (field Field) String() string

Represent a field as a string. Returns a string representation of a 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.

type Setter

type Setter interface {
	// Set the name of the database.
	SetName(name string)
	// Set the connection of the database.
	SetConnection(connection *sql.DB)
}

Representation of a database setter.

type Table

type Table[Type any] interface {
	Creator
	Setter
	Getter
	Inserter[Type]
	Accessor[Type]
	Remover[Type]
	Dropper
	Closer
	collections.Sized
}

Representation of a database table.

Directories

Path Synopsis
Connect provides a standardization of connecting to a database.
Connect provides a standardization of connecting to a database.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL