gomodel

command
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2015 License: MIT Imports: 17 Imported by: 0

README

gomodel

$ gomodel [OPTIONS] DIR|FILES...

Structure tags

  • table: table name
  • column: column name

Both using "-" to prevent from parsing.

SQL convertion

Why
  • I don't like to build sql in program manually
  • I don't mention what the real table and column name is
  • Just writing sql
Synax
type User struct {
    Id       string `table:"user" column:"user_id"`
    Name     string
    Password string
}
  • AST parsing: parsing sql AST
    Just use structure and field name replace table and column name. Example: replace

    SELECT user_id, name, password FROM user
    

    with

    SELECT Id, Name, Password FROM User
    
  • Simple parsing: simple lexing

    • {Structure} as table
    • {Structure:Field, Field} as column, column
    • {Structure.Field, Field} as table.column, table.column

    Example: replace

    SELECT user_id, name, password FROM user
    

    with

    SELECT {User:Id, Name, Password} FROM {User}
    

The only reason to use simple parsing is that AST parsing is not enough tested, AST parsing is enabled by default, use -AST=false to enable simple parsing.

Position

sql should be put in function documents, and start with //gomodel

  • simple
//gomodel sqlname = SELECT Id, Name, Password FROM User
  • block
//gomodel sqlname = [
//  SELECT
//  Id, Name, Password
//  FROM
//  User
//]

The form of first and last line can't be changed, others will be joined with an " ".

Output

see model.tmpl.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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