Code Monkey home page Code Monkey logo

modeltools's Introduction

Modeltools

GO语言连接Mysql生成对应的model,包括对应字段类型、注释等。生成基础的结构体,不局限于某一个ORM。

源码码地址---------

生成示例---------

  package models

  // 管理员表
  type AdminInfo struct {
  	Id int `json:"id"` 
  	Name string `json:"name"` // 姓名
  	Username string `json:"username"` // 用户名 
  	Password string `json:"password"` // 密码
  	RoleInfoId int `json:"role_info_id"` // 角色ID
  	Status int8 `json:"status"` // -1删除,0正常,1禁用
  }

参数配置--------conf.go

  package conf
  
  // model保存路径
  const ModelPath = "./models/"
  // 是否覆盖已存在model
  const ModelReplace = true
  // 数据库驱动
  const DriverName = "mysql"
  
  type DbConf struct {
  	Host   string
  	Port   string
  	User   string
  	Pwd    string
  	DbName string
  }
  // 数据库链接配置
  var MasterDbConfig DbConf = DbConf{
  	Host:   "127.0.0.1",
  	Port:   "3306",
  	User:   "root",
  	Pwd:    "long",
  	DbName: "mvideo",
  }

生成model--------

package main

import (
	"modeltools/dbtools"
	"modeltools/generate"
)


func main() {
	//初始化数据库
	dbtools.Init()
	//generate.Genertate() //生成所有表信息
	generate.Genertate("admin_info","video_info") //生成指定表信息,可变参数可传入多个表名
}

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.