dmltogo

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

README

dmltogo

Generate go struct by create sql DML.

Doc

Example:
dmltogo.DmlToGo(`CREATE TABLE Persons (
                     PersonID int,
                     LastName varchar(255),
                     FirstName varchar(255),
                     Address varchar(255),
                     City varchar(255) 
                 );`)

Output:

package model

type Person struct {
	Address   string `gorm:"column:Address" json:"Address"`
	City      string `gorm:"column:City" json:"City"`
	FirstName string `gorm:"column:FirstName" json:"FirstName"`
	LastName  string `gorm:"column:LastName" json:"LastName"`
	PersonID  int    `gorm:"column:PersonID" json:"PersonID"`
}

// TableName sets the insert table name for this struct type
func (p *Person) TableName() string {
	return "Persons"
}

Documentation

Overview

Package dmltogo A util can help to generate go struct by Create SQL DML. Input: create sql; Output: golang struct.

Example
package main

import (
	"log"

	"github.com/mnhkahn/dmltogo"
)

func main() {
	res, err := dmltogo.DmlToGo(`CREATE TABLE Persons (
                     PersonID int,
                     LastName varchar(255),
                     FirstName varchar(255),
                     Address varchar(255),
                     City varchar(255) 
                 );`)
	log.Println(res, err)
	/*  res is:
	package model

	type Person struct {
		Address   string `gorm:"column:Address" json:"Address"`
		City      string `gorm:"column:City" json:"City"`
		FirstName string `gorm:"column:FirstName" json:"FirstName"`
		LastName  string `gorm:"column:LastName" json:"LastName"`
		PersonID  int    `gorm:"column:PersonID" json:"PersonID"`
	}

	// TableName sets the insert table name for this struct type
	func (p *Person) TableName() string {
		return "Persons"
	}
	*/
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DmlToGo

func DmlToGo(dml string) ([]byte, error)

DmlToGo uses create sql to generate golang struct with gorm tags.

Types

This section is empty.

Jump to

Keyboard shortcuts

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