All Projects → ezbuy → ezorm

ezbuy / ezorm

Licence: Apache-2.0 license
schema first orm for Go

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to ezorm

codemagic-sample-projects
A collection of sample apps built with Codemagic CI/CD. Please see the codemagic.yaml file for a sample workflow configuration.
Stars: ✭ 82 (+78.26%)
Mutual labels:  yaml
contact-officials
Form definitions powering Resistbot's electronic deliveries to elected officials in the United States.
Stars: ✭ 29 (-36.96%)
Mutual labels:  yaml
climatecontrol
Python library for loading settings and config data from files and environment variables
Stars: ✭ 20 (-56.52%)
Mutual labels:  yaml
ufw
A minimalist framework for rapid server side applications prototyping in C++ with dependency injection support.
Stars: ✭ 19 (-58.7%)
Mutual labels:  yaml
stein
A linter for config files with a customizable rule set
Stars: ✭ 92 (+100%)
Mutual labels:  yaml
openapi-specification
Pinnacle REST API Open API Specification (swagger)
Stars: ✭ 20 (-56.52%)
Mutual labels:  yaml
havener
/ˈheɪvənə/ - Think of it as a swiss army knife for Kubernetes tasks
Stars: ✭ 296 (+543.48%)
Mutual labels:  yaml
kunnan.github.io
@zhangkn
Stars: ✭ 13 (-71.74%)
Mutual labels:  yaml
urlshort
Ex 2 - Create an http.Handler that forwards paths to other URLs
Stars: ✭ 114 (+147.83%)
Mutual labels:  yaml
ansible-taskrunner
Ansible Taskrunner - ansible-playbook wrapper with YAML-abstracted python click cli options!
Stars: ✭ 14 (-69.57%)
Mutual labels:  yaml
exenv
Exenv makes loading environment variables from external sources easy.
Stars: ✭ 35 (-23.91%)
Mutual labels:  yaml
yamlinc
Compose multiple YAML files into one with $include tag. Split Swagger/OpenAPI into multiple YAML files.
Stars: ✭ 103 (+123.91%)
Mutual labels:  yaml
ogrants
Open grants list
Stars: ✭ 96 (+108.7%)
Mutual labels:  yaml
cfg-rs
A Configuration Library for Rust Applications
Stars: ✭ 18 (-60.87%)
Mutual labels:  yaml
awesome-yaml
YAML awesomeness
Stars: ✭ 36 (-21.74%)
Mutual labels:  yaml
smacha
SMACHA is a meta-scripting, templating, and code generation engine for rapid prototyping of ROS SMACH state machines.
Stars: ✭ 15 (-67.39%)
Mutual labels:  yaml
artemis cli
A command-line application for tutors to more productively grade programming excises on ArTEMiS
Stars: ✭ 12 (-73.91%)
Mutual labels:  yaml
transfer
Converts from one encoding to another. Supported formats HCL ⇄ JSON ⇄ YAML⇄TOML⇄XML⇄plist⇄pickle⇄properties ...
Stars: ✭ 70 (+52.17%)
Mutual labels:  yaml
Textrude
Code generation from YAML/JSON/CSV models via SCRIBAN templates
Stars: ✭ 79 (+71.74%)
Mutual labels:  yaml
merge-yaml-cli
Node.js CLI utility for merging YAML files
Stars: ✭ 14 (-69.57%)
Mutual labels:  yaml

ezorm.v2

parser e2e CodeQL

Why another ORM for Go ?

With many years Go development experience in ezbuy , we find that define db schema first and share this schema within the project members or DBAs is really an advanced idea , like Protobuf for API-oriented development.

And the idea seems not alone within the Go community , projects like ent-go prove that there is a way to make a best-practice for Go ORM(like) Programming.

ezorm was built with this key idea in mind , but we describe the database schema as YAML file (or raw SQL file) , and the builtin generator(also the compiler) can generate some safe and most-used database operating methods for us , which lets business developers to focus on the business logic , rather than the bored CRUD .

Support Database

  • MySQL
    • driver: db: mysql
    • driver: db: mysqlr
  • MongoDB (v4.2+)
  • Redis(deprecated since v2)
  • SQL Server(deprecated since v2)
  • 3rd customized plugin

Schema

See full list of schema in our doc .

YAML Schema

Schema is defined with YAML file like:

Blog:
  db: mongo
  fields:
    - Title: string
    - Hits: int32
    - Slug: string
      flags: [unique]
    - Body: string
    - User: int32
    - CreateDate: datetime
      flags: [sort]
    - IsPublished: bool
      flags: [index]
  indexes: [[User, IsPublished]]

Id field will be automatically included for mongo/mysql.

SQL Schema

SQL Schema is introduced in v2 , and tries to help with raw query , like table JOIN , which can not be handled properly by YAML schema.

Inspired by sqlc's great AST analysis , we can extract the AST of SQL like:

SELECT
  name
FROM test_user
WHERE name = "me";

and generates the following Go Code :

type GetUserResp struct {
	Name string `sql:"name"`
}

type GetUserReq struct {
	Name string `sql:"name"`
}

func (req *GetUserReq) Params() []any {
	var params []any

	params = append(params, req.Name)

	return params
}

const _GetUserSQL = "SELECT `name` FROM `test_user` WHERE `name`=?"

// GetUser is a raw query handler generated function for `example/mysql_people/sqls/get_user.sql`.
func (*sqlMethods) GetUser(ctx context.Context, req *GetUserReq) ([]*GetUserResp, error) {

	query := _GetUserSQL

	rows, err := db.MysqlQuery(query, req.Params()...)
	if err != nil {
		return nil, err
	}
	defer rows.Close()

	var results []*GetUserResp
	for rows.Next() {
		var o GetUserResp
		err = rows.Scan(&o.Name)
		if err != nil {
			return nil, err
		}
		results = append(results, &o)
	}
	return results, nil
}

Usage

ezorm requires Go 1.18 or later.

	$ go install github.com/ezbuy/ezorm/v2
	$ ezorm gen -i blog.yaml -o .

To generate codes, for model like Blog, a blog manager will be generated, supporting ActiveRecord like:

p := blog.BlogMgr.NewBlog()
p.Title = "I like ezorm"
p.Slug = "ezorm"
p.Save()

p, err := blog.BlogMgr.FindBySlug("ezorm")
if err != nil {
  // handle error
}
fmt.Println("%v", p)
page.PageMgr.RemoveByID(p.Id())

_, err = blog.BlogMgr.FindBySlug("ezorm")
if err == nil {
  // handle error
}

use ezorm -h for more help

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].