Skip to content

hongyuan-wang/simple-sharding

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

☕️ A simple database shard middleware

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published