Skip to content
☕️ A simple database shard middleware
Branch: master
Clone or download
Latest commit 3a0af0b Aug 6, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src simplify spring config Aug 6, 2017
.gitignore support bazel May 10, 2017
.travis.yml use 127.0.0.1 Apr 11, 2017
BUILD support bazel May 10, 2017
README.md add checklist Aug 6, 2017
WORKSPACE support bazel May 10, 2017
pom.xml simplify spring config Aug 6, 2017

README.md

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

<dependency>
  <groupId>com.yuanwhy</groupId>
  <artifactId>simple-sharding</artifactId>
  <version>0.0.1-SNAPSHOT</version>
</dependency>

4. Set logic datasource and physic datasources

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:simple-sharding="http://yuanwhy.com/schema/simple-sharding"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd http://yuanwhy.com/schema/simple-sharding http://yuanwhy.com/schema/simple-sharding.xsd">

    <simple-sharding:hashShardingRule id="hashShardingRule" dbCount="2" tableCount="2" fieldNameForDb="role"
                                      fieldNameForTable="id"/>

    <simple-sharding:logicDataSource id="dataSource"
                                     name="passport"
                                     shardingRule="hashShardingRule">
        <simple-sharding:physicalDataSource name="passport_0" jdbcUrl="jdbc:mysql://127.0.0.1:3306/passport_0"
                                            user="root" password=""/>
        <simple-sharding:physicalDataSource name="passport_1" jdbcUrl="jdbc:mysql://127.0.0.1:3306/passport_0"
                                            user="root" password=""/>
    </simple-sharding:logicDataSource>


</beans>

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

Document

Simple-Sharding 中文

References

Todo

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

License

Apache License, Version 2.0

You can’t perform that action at this time.