1 Star 0 Fork 1

数据库相关 / simple-sharding

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

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

# Simple-Sharding [![Build Status](https://travis-ci.org/yuanwhy/simple-sharding.svg?branch=master)](https://travis-ci.org/yuanwhy/simple-sharding) [![Join the chat at https://gitter.im/yuanwhy/simple-sharding](https://badges.gitter.im/yuanwhy/simple-sharding.svg)](https://gitter.im/yuanwhy/simple-sharding?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) 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 ```xml <dependency> <groupId>com.yuanwhy</groupId> <artifactId>simple-sharding</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> ``` #### 4. Set logic datasource and physic datasources ```xml <?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 中文](http://www.jianshu.com/p/9784a3d4c7a8) [References](http://yuanwhy.com/tags/%E5%88%86%E5%BA%93%E5%88%86%E8%A1%A8/) ## Todo - [x] Support Spring custom namespace - [ ] Finish other methods - [ ] Support multiple tables in one datasource ## License Apache License, Version 2.0

简介

暂无描述 展开 收起
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ALiBaBaKaiYuan/simple-sharding.git
git@gitee.com:ALiBaBaKaiYuan/simple-sharding.git
ALiBaBaKaiYuan
simple-sharding
simple-sharding
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891