GithubHelp home page GithubHelp logo

ezorm's Introduction

ezorm

ezorm is an code-generation based ORM lib for golang, supporting mongodb/sql server/mysql/redis.

data model 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 server.

Setup

ezorm templates are defined in tpl folder and managed via go-bindata.

After go get github.com/ezbuy/ezorm, you should do:

make init
make debugTpl

to initialize the dependencies & link tpl for debug usages.

Usage

go install github.com/ezbuy/ezorm
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 {
	t.Error("find fail")
}
fmt.Println("%v", p)
page.PageMgr.RemoveByID(p.Id())

_, err = blog.BlogMgr.FindBySlug("ezorm")
if err == nil {
	t.Error("delete fail")
}

use ezorm -h for more help ezorm genmsyaml -d="server=...;user id=...;password=...;DATABASE=..." -t=... -o=... -p=... to generate yaml file ezorm genmsorm -d="server=...;user id=...;password=...;DATABASE=..." -t=... -o=... -p=... to generate orm go file directly

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.