simple-sharding

by yuanwhy

yuanwhy /simple-sharding

☕️ A simple database shard middleware

131 Stars 42 Forks Last release: Not found 44 Commits 0 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Simple-Sharding

Build Status Join the chat at https://gitter.im/yuanwhy/simple-sharding License

A simple database shard middleware, based on JDBC API. Applications can scale database by using new DataSource with simple-sharding. This project is not finished, and feel free to study.

Features

  • Transaction in single database shard
  • Sharding
  • Rewriting rules

Quick Start

1. Get source code

git clone https://github.com/yuanwhy/simple-sharding.git

and then execute

test/create_schema.sql
to init data.

2. Install simple-sharding to you local repository by

mvn clean install

3. Add artifact dependency

  com.yuanwhy
  simple-sharding
  0.0.1-SNAPSHOT

4. Set logic datasource and physic datasources

<hashshardingrule id="hashShardingRule" dbcount="2" tablecount="2" fieldnamefordb="role" fieldnamefortable="id"></hashshardingrule>

<logicdatasource id="dataSource" name="passport" shardingrule="hashShardingRule">
    <physicaldatasource name="passport_0" jdbcurl="jdbc:mysql://127.0.0.1:3306/passport_0" user="root" password=""></physicaldatasource>
    <physicaldatasource name="passport_1" jdbcurl="jdbc:mysql://127.0.0.1:3306/passport_0" user="root" password=""></physicaldatasource>
</logicdatasource>

5. Feel free to use JDBC API or ORM framework (e.g. MyBatis ) to execute your SQL

Document

Simple-Sharding 中文

References

Todo

  • [x] Support Spring custom namespace
  • [ ] Finish other methods
  • [ ] Support multiple tables in one datasource

License

Apache License, Version 2.0

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.