πŸ“š godal - Awesome Go Library for Go Generate Tools

Go Gopher mascot for godal

Generate orm models corresponding to golang by specifying sql ddl file, which can be used by gorm.

🏷️ Go Generate Tools
πŸ“‚ Plugin for text editors and IDEs.
⭐ 18 stars
View on GitHub πŸ”—

Detailed Description of godal

GoDoc Codecov.io Go Report Card Mentioned in Awesome Go

godal

English | δΈ­ζ–‡

godal provides the ability to generate specific golang code. The goal is to enable developers to write fast code in an expressive way.

Functions:

  1. Generate orm model corresponding to golang by specifying sql ddl file, which can be used by gorm.
  2. Update later

godal has been added to awesome-go, MR link

Usage Documentation

Installation

Using this package requires a working Go environment. See the install instructions for Go.

Go Modules are required when using this package. See the go blog guide on using Go Modules.

How to install godal?

git clone [email protected]:mafulong/godal.git
cd godal
go install

Make sure that you can have result when call commendwhich godal

SQL to golang model

godal gen model --database {your databaseName} {your sqlFile}

Example

You can enter the test directory in this repo.

godal gen model --database testdb gen_model.sql

What you can get?

example file1:

package testdb

import "time"

type TestTb1 struct {
	TestId         int       `gorm:"Column:test_id" json:"test_id"`
	TestTitle      string    `gorm:"Column:test_title" json:"test_title"`
	TestAuthor     string    `gorm:"Column:test_author" json:"test_author"`
	SubmissionDate time.Time `gorm:"Column:submission_date" json:"submission_date"`
}

func (TestTb1) TableName() string {
	return "test_tb1"
}

License

The MIT License (MIT). Please see License File for more information.