Giter Site home page Giter Site logo

sql2gorm's Introduction

sql2gorm

sql2gorm is a command line tool to generate Go code with Gorm Tag and Json Tag from SQL.

Web tool: https://sql2gorm.mccode.info/

Download

go get -u github.com/cascax/sql2gorm/...

Usage (Command Line)

get struct from a sql file and write struct to the file

sql2gorm -f file.sql -o model.go

get struct from mysql

sql2gorm -db-dsn=root:123456@/msir -db-table=fund_info

get struct from arguments

sql2gorm -sql="CREATE TABLE person_info (
  age INT(11) unsigned NULL,
  id BIGINT(11) PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT '这是id',
  name VARCHAR(30) NOT NULL DEFAULT 'default_name' COMMENT '这是名字',
  created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  sex VARCHAR(2) NULL,
  num INT(11) DEFAULT 3 NULL,
  comment TEXT
  ) COMMENT='person info';"

Library usage

import "github.com/cascax/sql2gorm/parser"

sql := `CREATE TABLE t_person_info (
  id BIGINT(11) PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT 'primary id',
  name VARCHAR(30) NOT NULL DEFAULT 'default_name',
  created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  age INT(11) unsigned NULL,
  sex VARCHAR(2) NULL
  );`
data, err := parser.ParseSql(sql, WithTablePrefix("t_"), WithJsonTag())

sql2gorm's People

Contributors

cascax avatar

Watchers

James Cloos 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.