Git Product home page Git Product logo

tidb-lite's Introduction

tidb-lite test

English README

tidb-lite 是一个库,可以方便地使用该库在 golang 应用或者单元测试中创建 mocktikv 模式的 TiDB。

提供的接口

  • func NewTiDBServer(options *Options) (*TiDBServer, error)

    创建一个 TiDB Server,使用 options 来设置 TiDB 存储数据的路径和服务的端口号。

  • func GetTiDBServer() (*TiDBServer, error)

    获取已经创建的 TiDB Server。

  • func (t *TiDBServer) CreateConn() (*sql.DB, error)

    获取一个 TiDB 的链接。

  • func (t *TiDBServer) Close()

    关闭 TiDB 服务。

  • func (t *TiDBServer) CloseGracefully()

    优雅地关闭 TiDB 服务。

使用示例

可以通过 example 路径下的示例代码了解 tidb-lite 的使用方法。

example.go 中定义了一个函数 GetRowCount 计算指定表中符合条件的数据的行数。 在 example_test.go 中使用以下代码创建 TiDB Server 并获取数据库链接:

tidbServer, err := tidblite.NewTiDBServer(tidblite.NewOptions(c.MkDir()))
c.Assert(err, IsNil)
defer tidbServer.Close()

dbConn, err := tidbServer.CreateConn()
c.Assert(err, IsNil)

然后就可以使用链接 dbConn 生成测试数据,对函数 GetRowCount 进行测试。

注意

tidb-lite 只允许同一时刻运行一个 TiDB 实例,需要保证已经创建的 TiDB 实例 close 后再创建新的实例。

tidb-lite's People

Contributors

wangxiangustc avatar ailinkid avatar erikthorselius avatar nange avatar tsthght 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.