model

package
v4.2.1-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2023 License: Apache-2.0 Imports: 1 Imported by: 1

Documentation

Overview

Package model for managing data access

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorNilInterface         = errors.New("interface is nil")
	ErrorNotFound             = errors.New("not found")
	ErrorMultipleRecordsFound = errors.New("multiple records found")
)

Functions

This section is empty.

Types

type Model

type Model interface {
	// Register a new model eg. User struct, Order struct
	Register(v interface{}) error
	// Create a new object. (Maintains indexes set up)
	Create(v interface{}) error
	// Update will take an existing object and update it.
	Update(v interface{}) error
	// Read a result by id e.g &User{ID: 1}
	Read(v interface{}) error
	// Deletes a record
	Delete(v interface{}) error
	// Query with a where clause
	Query(res interface{}, where ...interface{}) error
}

Model represents a place where data can be saved to and queried from.

var (
	DefaultModel Model
)

type Option

type Option func(*Options)

func WithAddress

func WithAddress(ns string) Option

WithAddress sets the database address

func WithDatabase

func WithDatabase(db string) Option

WithDatabase sets the default database for queries

func WithTable

func WithTable(t string) Option

WithTable sets the default table for queries

type Options

type Options struct {
	// Database sets the default database
	Database string
	// Table sets the default table
	Table string
	// Address to scope to
	Address string
}

Directories

Path Synopsis
Package sql is for a sql database model
Package sql is for a sql database model

Jump to

Keyboard shortcuts

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