Git Product home page Git Product logo

bingo-orm's Introduction

bingo-orm

bingo-orm 是 bingo 框架下的一个子模块,可以快速沟通数据库

特性:

  • 链式操作
  • 模型
  • 数据库迁移
  • 一键开启数据库连接池
  • 数据库假数据填充

使用方式

  1. 连接数据库
  • 单一连接

     // 输入数据
     config := make(map[string]string)
     config["db_username"] = "root"
     config["db_password"] = ""
     config["db_host"] = "127.0.0.1"
     config["db_port"] = "3306"
     config["db_name"] = "test"
     config["db_charset"] = "utf8"
     c := db.NewConnector(config)  // 传入连接参数,可以得到一个Mysql连接,使用其他数据库则调用其他的新建数据库连接的方法        
  • 使用数据库连接池(待定)

  1. 创建数据库

在连接器上调用Schema() 方法获得一个 SchemaBuilder ,用来对数据库以及数据表结构进行操作

   res, err := c.Schema().CreateDatabaseIfNotExists("test")  // 第二个参数是字符集,第三个参数是排序规则
  1. 创建数据表

SchemaBuilder 上提供了创建表的方法,在回调函数中进行表结构的定义

    err := c.Schema().CreateTable("test", func(table db.IBlueprint) {
    		table.Increments("id").Comment("自增id")  // 设置备注与主键
    		table.String("name").Comment("姓名")  
    		table.Integer("age").Nullable().Comment("年龄") // 允许为空
    		
    		// 添加普通索引  _index
          table.Index("user_id")
          // 添加唯一索引  _unique_index
          table.UniqueIndex("user_id")
          // 添加组合索引 
          table.Index("user_id","name")
          // 添加全文索引,只对MyISAM表有效
          table.FullTextIndex("user_id")
   })

接下来的任务

  • 创建表可以添加各种类型的字段(float double 等)
  • 更改表结构
  • 对表进行增删改
  • 重新组织结果集(ToMapList ToStringMapList)
  • 对表进行简单查询
  • mysql事务处理
  • 内外连接,完全连接
  • 实现多态(暂时不实现)
  • 对表查询时指定优先级
  • 对表进行复杂查询(子表等)
  • 添加模型处理(对模型增加观察者,模型与db进行关联,底层使用db进行操作)
  • 读写分离
  • 连接池
  • 整理说明文档

bingo-orm's People

Contributors

silsuer 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.