neormgo

package module
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2025 License: MIT Imports: 10 Imported by: 0

README

Neorm Go - All-in-one orm

Neorm Go is a imperative orm that makes you imperatively build and execute queries.

It includes this functionalities:

  • Query Builder
  • Schema Builder
  • Table Builder,
  • Alter Queries Builder
  • User Queries Builder
  • Actual sql driver

It has almost everything that an engineer can want from orm and it's Query, schema And table builders tested in different situations.

It supports mysql, postgresql, sqlite and microsoft sql server.

Examples

Initialization

// import that liblary:

import (
    "github.com/Necoo33/neorm-go"
)

Database Connection

// ...

neorm := orm.Neorm{}

database, err := database.Connect("username:password@tcp(127.0.0.1:3306)/schema_name", "mysql") // schema name not necessary

if err != nil {
// do your error checking
}

// ...

Building Queries

There is some examples for building and executing CRUD queries. You can do all of them with the same instance imperatively, when you invoke .Select(), .Insert(), .Update() and .Delete() methods query building will be restarted. Less allocation, more performance.

SELECT query

// ...

database = database.Select([]string{"id", "title", "description", "published", "likes", "comments"})
database.Table("blogs")
database.Where("likes", ">", 50)
database.And("published", "=", true)
database.Finish()

// than execute that query:

posts, err := database.Execute()

if err != nil {
// error checking    
}

// it returns rows as []map[string]interface{}, that means you can reach rows similar to php's associative array':

for i, post := range posts {
fmt.Printf("%d. row: \n", i+1)
fmt.Printf("Post title: %s\n", post["title"])
fmt.Printf("Published: %v\n", post["published"])
fmt.Printf("Likes: %d\n", post["likes"])
}

// ...

INSERT Query

columns := []string{"id", "description", "title"} // all your columns

values := []interface{}{1, "lorem ipsum dolor sit amet", "consectetur adipiscing elit!"} // all your values ordinarily

insert := database.Insert(columns, values)
insert.Table("blogs")
insert.Finish()
insert.Execute()

lid, err := insert.LastInsertId()

if err != nil {
// error checking  
}

Update Query

database.Update()
database.Table("blogs")
database.Set("published", false)
database.Where("id", "=", 1)
database.Finish()
database.Execute()

ra, err := insert.RowsAffected()

if err != nil {
// error checking  
}

Delete Query

database.Delete()
database.Table("blogs")
database.Where("id", "=", 10)
database.Finish()
database.Execute()

ra, err := insert.RowsAffected()

if err != nil {
// error checking  
}

Schema Creation

Creating a schema is as simple as it is:


schema := database.CreateSchema("neorm_test")
schema.Finish()

err = schema.QueryDrop()

if err != nil {
// do your error check
}

Table Creation

Table creation is also easy and very readable. Such as that:


// initialize the table or continue from another Neorm instance:

table := database.CreateTable("blogs").IfNotExist()

table.AddColumn("id")
table.Type("int")
table.PrimaryKey()
table.NotNull()

table.AddColumn("title")
table.Type("VARCHAR(30)")
table.NotNull()
table.Unique()

table.AddColumn("published")
table.Type("BOOLEAN")
table.Default(true)

table.AddColumn("description")
table.Type("TEXT(1000)")
table.Null()

table.AddColumn("user_id")
table.Type("TINYINT")
table.NotNull()

// make user_id column a foreign key for "id" column of "users" table:

type References struct {
Users string
}

table.ForeignKey("user_id", References{Users: "id"})

table.Finish()

// This codes create this query:

/* 

CREATE TABLE IF NOT EXIST (
    id INT PRIMARY KEY NOT NULL,
    title VARCHAR(30) NOT NULL UNIQUE,
    published BOOLEAN DEFAULT true,
    description TEXT(1000) NULL,
    user_id TINYINT NOT NULL
    FOREIGN KEY user_id REFERENCES users(id)
);

*/

That orm is built especially for my personal use but anyone who wants to empower themselves with neorm free to use it. Contributions or feature requests are welcome.

Documentation

Index

Constants

View Source
const Version = "1.9.0"

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

type Driver int
const (
	Mysql Driver = iota
	Postgresql
	Sqlite3
	MicrosoftSqlServer
)

type Neorm

type Neorm struct {
	Schema string
	Query  string

	Pool *sql.DB
	Tx   *sql.Tx
	// contains filtered or unexported fields
}

func (*Neorm) Add

func (orm *Neorm) Add(something string) Neorm

func (*Neorm) AddColumn

func (orm *Neorm) AddColumn(name string) Neorm

func (*Neorm) AddConstraint

func (orm *Neorm) AddConstraint(constraint string) Neorm

func (*Neorm) AddFulltextIndex

func (orm *Neorm) AddFulltextIndex(column string) Neorm

func (*Neorm) AddIndex

func (orm *Neorm) AddIndex(indexName, column string) Neorm

func (*Neorm) AddPrimaryKey

func (orm *Neorm) AddPrimaryKey(column string) Neorm

func (*Neorm) AddSpatialIndex

func (orm *Neorm) AddSpatialIndex(column string) Neorm

func (*Neorm) AddUniqueIndex

func (orm *Neorm) AddUniqueIndex(indexName, column string) Neorm

func (*Neorm) After

func (orm *Neorm) After(columnFromAfter string) Neorm

func (*Neorm) AllUsers

func (orm *Neorm) AllUsers() Neorm

func (*Neorm) AlterTable

func (orm *Neorm) AlterTable(name string) Neorm

func (*Neorm) And

func (orm *Neorm) And(column, mark string, value interface{}) Neorm

func (*Neorm) AndExpr added in v1.4.0

func (orm *Neorm) AndExpr(column, mark string, expr string) Neorm

func (*Neorm) AutoIncrement

func (orm *Neorm) AutoIncrement() Neorm

func (*Neorm) Begin added in v1.1.3

func (orm *Neorm) Begin() error

func (*Neorm) Between added in v1.6.0

func (orm *Neorm) Between(first, second interface{}) Neorm

func (*Neorm) Call added in v1.1.0

func (orm *Neorm) Call(callType, procedure, resultAlias string, args ...interface{}) Neorm

func (*Neorm) ChangeColumn

func (orm *Neorm) ChangeColumn(oldColumn, newColumn string) Neorm

func (*Neorm) CharacterSet

func (orm *Neorm) CharacterSet(characterSet string) Neorm

func (*Neorm) Check

func (orm *Neorm) Check(condition string) Neorm

func (*Neorm) Close

func (orm *Neorm) Close()

func (*Neorm) CloseParenthesis

func (orm *Neorm) CloseParenthesis() Neorm

func (*Neorm) Comment

func (orm *Neorm) Comment(comment string) Neorm

func (*Neorm) Commit added in v1.1.3

func (orm *Neorm) Commit() error

func (*Neorm) Connect

func (orm *Neorm) Connect(connString string, driver string) (Neorm, error)

func (*Neorm) Count added in v1.1.0

func (orm *Neorm) Count(table string) Neorm

func (*Neorm) CreateSchema

func (orm *Neorm) CreateSchema(name string) Neorm

func (*Neorm) CreateTable

func (orm *Neorm) CreateTable(name string) Neorm

func (*Neorm) CreateUser

func (orm *Neorm) CreateUser(name, scope string) Neorm

func (*Neorm) CrossJoin

func (orm *Neorm) CrossJoin(table string) Neorm

func (*Neorm) CustomDeleteQuery added in v1.9.0

func (orm *Neorm) CustomDeleteQuery(query string) Neorm

func (*Neorm) CustomInsertQuery added in v1.9.0

func (orm *Neorm) CustomInsertQuery(query string) Neorm

func (*Neorm) CustomKeyword

func (orm *Neorm) CustomKeyword(keywordAndValue string) Neorm

func (*Neorm) CustomQuery

func (orm *Neorm) CustomQuery(query string) Neorm

func (*Neorm) CustomSelectQuery added in v1.9.0

func (orm *Neorm) CustomSelectQuery(query string) Neorm

func (*Neorm) CustomUpdateQuery added in v1.9.0

func (orm *Neorm) CustomUpdateQuery(query string) Neorm

func (*Neorm) Default

func (orm *Neorm) Default(value interface{}) Neorm

func (*Neorm) DefaultOnNull

func (orm *Neorm) DefaultOnNull(value interface{}) Neorm

func (*Neorm) Delete

func (orm *Neorm) Delete() Neorm

func (*Neorm) DisableKeys

func (orm *Neorm) DisableKeys() Neorm

func (*Neorm) Drop

func (orm *Neorm) Drop(something string) Neorm

func (*Neorm) DropColumn

func (orm *Neorm) DropColumn(column string) Neorm

func (*Neorm) DropConstraint

func (orm *Neorm) DropConstraint(constraint string) Neorm

func (*Neorm) DropForeingKey

func (orm *Neorm) DropForeingKey(foreignKey string) Neorm

func (*Neorm) DropIndex

func (orm *Neorm) DropIndex(index string) Neorm

func (*Neorm) DropPrimaryKey

func (orm *Neorm) DropPrimaryKey() Neorm

func (*Neorm) DropUser

func (orm *Neorm) DropUser(user, scope string) Neorm

func (*Neorm) EnableKeys

func (orm *Neorm) EnableKeys() Neorm

func (*Neorm) Engine

func (orm *Neorm) Engine(engine string) Neorm

func (*Neorm) Enum

func (orm *Neorm) Enum(values []string) Neorm

func (*Neorm) Execute

func (orm *Neorm) Execute() error

func (*Neorm) Finish

func (orm *Neorm) Finish() Neorm

func (*Neorm) First

func (orm *Neorm) First() Neorm

func (*Neorm) FlushPrivileges

func (orm *Neorm) FlushPrivileges() Neorm

func (*Neorm) ForeignKey

func (orm *Neorm) ForeignKey(column string, referenceStruct interface{}) Neorm

func (*Neorm) ForeignKeyWithConstraint

func (orm *Neorm) ForeignKeyWithConstraint(constraint, column string, referenceStruct interface{}) Neorm

func (*Neorm) Generated

func (orm *Neorm) Generated() Neorm

func (*Neorm) GeneratedAlways

func (orm *Neorm) GeneratedAlways(condition string) Neorm

func (*Neorm) GrantPrivileges

func (orm *Neorm) GrantPrivileges(privileges interface{}, schema string) Neorm

func (*Neorm) GroupBy added in v1.7.0

func (orm *Neorm) GroupBy(columns ...string) Neorm

func (Neorm) IfNotExist

func (orm Neorm) IfNotExist() Neorm

func (*Neorm) In

func (orm *Neorm) In(inType string, column string, values []any) Neorm

func (*Neorm) Index

func (orm *Neorm) Index(index interface{}) Neorm

func (*Neorm) InnerJoin

func (orm *Neorm) InnerJoin(table string, left string, mark string, right string) Neorm

func (*Neorm) Insert

func (orm *Neorm) Insert(columns []string, values interface{}) Neorm

func (*Neorm) Invisible

func (orm *Neorm) Invisible() Neorm

func (*Neorm) LastInsertId

func (orm *Neorm) LastInsertId() (string, error)

func (*Neorm) LeftJoin

func (orm *Neorm) LeftJoin(table string, left string, mark string, right string) Neorm

func (*Neorm) Length

func (orm *Neorm) Length() int64

func (*Neorm) Like

func (orm *Neorm) Like(queryType, column, operand, pattern string) Neorm

func (*Neorm) Limit

func (orm *Neorm) Limit(limit int) Neorm

func (*Neorm) LockUserAccount

func (orm *Neorm) LockUserAccount(user, scope string) Neorm

func (*Neorm) ModifyColumn

func (orm *Neorm) ModifyColumn(column string) Neorm

func (*Neorm) NaturalJoin

func (orm *Neorm) NaturalJoin(table string) Neorm

func (*Neorm) NotIn

func (orm *Neorm) NotIn(inType string, column string, values []any) Neorm

func (*Neorm) NotLike added in v1.8.0

func (orm *Neorm) NotLike(queryType, column, operand, pattern string) Neorm

func (*Neorm) NotNull

func (orm *Neorm) NotNull() Neorm

func (*Neorm) Null

func (orm *Neorm) Null() Neorm

func (*Neorm) Offset

func (orm *Neorm) Offset(offset int) Neorm

func (*Neorm) OnDelete

func (orm *Neorm) OnDelete(newValue string) Neorm

func (*Neorm) OnUpdate

func (orm *Neorm) OnUpdate(newValue string) Neorm

func (*Neorm) OpenParenthesis

func (orm *Neorm) OpenParenthesis(parenthesisType string) Neorm

func (*Neorm) Or

func (orm *Neorm) Or(column, mark string, value interface{}) Neorm

func (*Neorm) OrExpr added in v1.4.0

func (orm *Neorm) OrExpr(column, mark string, expr string) Neorm

func (*Neorm) OrderBy

func (orm *Neorm) OrderBy(column, ordering string) Neorm

func (*Neorm) OrderByField

func (orm *Neorm) OrderByField(column string, values []string) Neorm

func (*Neorm) OrderRandom

func (orm *Neorm) OrderRandom() Neorm

func (*Neorm) PasswordExpiration

func (orm *Neorm) PasswordExpiration(user, scope, expirationStr string) Neorm

func (*Neorm) PrimaryKey

func (orm *Neorm) PrimaryKey() Neorm

func (*Neorm) QueryDrop

func (orm *Neorm) QueryDrop() error

it's for queries that not get any feedback from if operation successfull. It doesn't do any preparations.

func (*Neorm) RenameColumn

func (orm *Neorm) RenameColumn(oldName, newName string) Neorm

func (*Neorm) RenameTable

func (orm *Neorm) RenameTable(newName string) Neorm

func (*Neorm) RenameUser

func (orm *Neorm) RenameUser(newName, newScope string) Neorm

func (*Neorm) Returning added in v1.3.1

func (orm *Neorm) Returning(column string) Neorm

func (*Neorm) RevokePrivileges

func (orm *Neorm) RevokePrivileges(privileges interface{}, schema string) Neorm

func (*Neorm) RightJoin

func (orm *Neorm) RightJoin(table string, left string, mark string, right string) Neorm

func (*Neorm) Rollback added in v1.1.3

func (orm *Neorm) Rollback() error

func (*Neorm) Rows

func (orm *Neorm) Rows() ([]map[string]interface{}, error)

func (*Neorm) RowsAffected

func (orm *Neorm) RowsAffected() (int64, error)

func (*Neorm) Select

func (orm *Neorm) Select(columns interface{}) Neorm

func (*Neorm) SelectFunction added in v1.3.3

func (orm *Neorm) SelectFunction(function string, args ...interface{}) Neorm

func (*Neorm) Set

func (orm *Neorm) Set(column string, value interface{}) Neorm

func (*Neorm) SetDefaultRole

func (orm *Neorm) SetDefaultRole(role string) Neorm

func (*Neorm) SetExpr added in v1.4.0

func (orm *Neorm) SetExpr(column, expr string) Neorm

func (*Neorm) SetPassword

func (orm *Neorm) SetPassword(password string) Neorm

func (*Neorm) ShowGrants

func (orm *Neorm) ShowGrants() Neorm

func (*Neorm) Spatial

func (orm *Neorm) Spatial() Neorm

func (*Neorm) Stored

func (orm *Neorm) Stored() Neorm

func (*Neorm) Table

func (orm *Neorm) Table(table string) Neorm

func (*Neorm) Type

func (orm *Neorm) Type(typeVal string) Neorm

func (*Neorm) Unique

func (orm *Neorm) Unique() Neorm

func (*Neorm) Unsigned

func (orm *Neorm) Unsigned() Neorm

func (*Neorm) Update

func (orm *Neorm) Update() Neorm

func (*Neorm) Use

func (orm *Neorm) Use(schema string) Neorm

func (*Neorm) UserInfos

func (orm *Neorm) UserInfos(username, scope, password string) Neorm

func (*Neorm) Virtual

func (orm *Neorm) Virtual() Neorm

func (*Neorm) Where

func (orm *Neorm) Where(column, mark string, value interface{}) Neorm

func (*Neorm) WhereExpr added in v1.4.0

func (orm *Neorm) WhereExpr(column, mark string, expr string) Neorm

func (*Neorm) Zerofill

func (orm *Neorm) Zerofill() Neorm

type Row

type Row struct {
	Columns map[string]interface{}
}

Jump to

Keyboard shortcuts

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