orm

package
v0.2.24 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2023 License: MIT Imports: 1 Imported by: 1

README

DALgo ORM

Object-Relational Mapping (ORM) is a technique that lets you query and manipulate data from a database using an object-oriented paradigm.

This ORM works hand to hand with DALgo DAL.

Firs of all you need to define fields of your data objects:

type user struct {
	Email     orm.StringField
	FirstName orm.StringField
	LastName  orm.StringField
}

// This will be used to query data
var User = user{
    FirstName: orm.NewStringField("fist_name"),
    LastName:  orm.NewStringField("last_name"),
    Email:     orm.NewStringField("email"),
}

Then indicate where the data stored (e.g. table or collection name):

func (v user) Collection() *dal.CollectionRef {
	return &dal.CollectionRef{
		Name: "users",
	}
}

Now you can create queries to database using strongly typed code.

For example imaging we'd like to select a user with specific email:

type row struct {
	FirstName string
	LastName string
}

query := dal.Select{
    From:  User.Collection(),
    Where: User.Email.EqualToString(email),
    Columns: query.Columns(User.FirstName.Name(), User.LastName.Name()),
    Into: func() any {
        return &row{}
    },
    Limit: 1,
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field interface {
	Name() string
	Type() string
	Required() bool
	CompareTo(operator dal.Operator, v dal.Expression) dal.Condition
}

Field defines field

type StringField

type StringField interface {
	Field
	EqualToString(s string) dal.Condition
}

StringField defines a string field

func NewStringField

func NewStringField(name string) StringField

NewStringField defines a new string field

Jump to

Keyboard shortcuts

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