Git Product home page Git Product logo

dbml-go's Introduction

DBML parser for Go

DBML-go is a Go parser for DBML syntax.

Go model generate

go install github.com/gzwillyy/dbml-go/cmd/dbml-gen-go-model@latest
Usage:
  dbml-gen-go-model [flags]

Flags:
  -E, --exclude string          regex for exclude "from" files. Only applied if "from" is a directory
  -t, --fieldtags stringArray   go field tags (default [db,json,mapstructure])
  -f, --from string             source of dbml, can be https://dbdiagram.io/... | fire_name.dbml (default "database.dbml")
      --gen-table-name          should generate "TableName" function
  -h, --help                    help for dbml-gen-go-model
  -o, --out string              output folder (default "model")
  -p, --package string          single for multiple files (default "model")
      --recursive               recursive search directory. Only applied if "from" is a directory
      --remember-alias          should remember table alias. Only applied if "from" is a directory

Example:

input:

// database.dbml
Table users as U {
  id int [pk, unique, increment] // auto-increment
  full_name varchar [not null, unique, default: 1]
  created_at timestamp
  country_code int
  Note: 'This is simple note'
}

Run:

mkdir -p model
dbml-gen-go-model -f database.dbml -o model -p model

output: model/users.table.go

// Code generated by dbml-gen-go-model. DO NOT EDIT.
// Supported by duythinht@2020
package model

// User is generated type for table 'users'
type User struct {
	ID          int    `db:"id" json:"id" mapstructure:"id"`
	FullName    string `db:"full_name" json:"full_name" mapstructure:"full_name"`
	CreatedAt   int    `db:"created_at" json:"created_at" mapstructure:"created_at"`
	CountryCode int    `db:"country_code" json:"country_code" mapstructure:"country_code"`
}

// table 'users' columns list struct
type __tbl_users_columns struct {
	ID          string
	FullName    string
	CreatedAt   string
	CountryCode string
}

// table 'users' metadata struct
type __tbl_users struct {
	Name    string
	Columns __tbl_users_columns
}

// table 'users' metadata info
var _tbl_users = __tbl_users{
	Columns: __tbl_users_columns{
		CountryCode: "country_code",
		CreatedAt:   "created_at",
		FullName:    "full_name",
		ID:          "id",
	},
	Name: "users",
}

// GetColumns return list columns name for table 'users'
func (*__tbl_users) GetColumns() []string {
	return []string{"id", "full_name", "created_at", "country_code"}
}

// T return metadata info for table 'users'
func (*User) T() *__tbl_users {
	return &_tbl_users
}

dbml-go's People

Contributors

duythinht avatar vanhtuan0409 avatar gzwillyy avatar srenatus avatar

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.