opao

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

opao

一个小巧,简单的ORM🌟A small, simple ORM

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsEmpty

func IsEmpty(err error) bool

IsEmpty checks if the error is due to an empty result

Types

type Action

type Action struct {
	Table string           // Name of the table
	Db    *Database        // Reference to the Database instance
	Elems map[string]*Elem // Mapping of field names to Elem objects
	Cache *Cache           // Cache object for the table
	Obj   any              // Object
}

Action represents a set of database operations

func (*Action) Delete

func (qt *Action) Delete(queryString string, queryValue ...any) error

Delete deletes database records based on the provided query string and values

func (*Action) Insert

func (qt *Action) Insert() error

Insert inserts data into the database using INSERT operation

func (*Action) Select

func (qt *Action) Select(queryString string, queryValue ...any) ([]any, error)

Select retrieves data from the database based on the provided query string and values

func (*Action) SelectOne

func (qt *Action) SelectOne(queryString string, queryValue ...any) error

SelectOne selects a single record from the database based on the provided query string and values

func (*Action) Update

func (qt *Action) Update(queryString string, queryValue ...any) error

Update updates the database record based on the provided query string and values

type Cache

type Cache struct {
	Table   string
	ObjType reflect.Type
	Elems   map[string]*Elem
	Db      *Database
}

func (*Cache) Use

func (cache *Cache) Use(obj any) *Action

type Database

type Database struct {
	Db     *sql.DB                 // Database connection object
	Caches map[reflect.Type]*Cache // Mapping of object types to caches
	RWLock sync.RWMutex            // Read-write lock
}

Database ORM Object

func NewDatabase

func NewDatabase(driverName, dataSourceName string) (*Database, error)

NewDatabase creates and initializes a new Database instance

func (*Database) Load

func (db *Database) Load(obj any, table string) *Cache

func (*Database) Use

func (db *Database) Use(obj any) *Action

type Elem

type Elem struct {
	Type  reflect.StructField
	Value reflect.Value
	Tag   string
	Name  string
}

func (*Elem) Get

func (elem *Elem) Get() any

func (*Elem) Set

func (elem *Elem) Set(val any)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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