Giter Club home page Giter Club logo

synbag's Introduction

synbag

synbag is..

  1. Simple shardingsphere library
  2. Simple shardingsphere REST API server

Build

mvn install

Usage

// =================
// Yaml style
// =================
SynbagConfig synbagConfig = SynbagConfig.loadAndConfigSynbag("synbag-config.yml");
DataSource shardingDatasource = synbagConfig.getShardingDatasource();
Connection connection = shardingDatasource.getConnection();
connection.close();

// =================
// Code style
// =================
SynbagConfig synbagConfig = new SynbagConfig();

// DataSource
DataSource[] datasources = ..;
synbagConfig.setDataSources(datasources);

// Sharding table
Map<String, ShardingTable> shardingTables = new HashMap<String, ShardingTable>();
ShardingTable shardingTable = new ShardingTable();
shardingTable.setShardingColumn("userid");
shardingTable.setShardingMethod("crc32");
shardingTables.put("user", shardingTable);
synbagConfig.setShardingTables(shardingTables); // Add sharding policy

// Broadcast table
List<String> broadcastTables = new ArrayList<String>();
synbagConfig.setBroadcastTables(broadcastTables); // Add broadcast policy

// Initialize
synbagConfig.init();

synbag-config.yml

sample config file

dataSources:
- !!org.apache.commons.dbcp2.BasicDataSource
  driverClassName: com.mysql.cj.jdbc.Driver
  url: jdbc:mysql://127.0.0.1:3306/shard01?autoReconnect=true
  username: shard01
  password: shard01
  maxTotal: 30
- !!org.apache.commons.dbcp2.BasicDataSource
  driverClassName: com.mysql.cj.jdbc.Driver
  url: jdbc:mysql://127.0.0.1:3306/shard02?autoReconnect=true
  username: shard02
  password: shard02
  maxTotal: 30

shardingTables:
  user:
    realTableName: user
    shardingColumn: userid
    shardingMethod: crc32
  user_log:
    shardingColumn: userid
    shardingMethod: crc32
broadcastTables: [config]

Usage as REST API

Usage: <main class> [-c=<configFile>] [-p=<port>] [-r=<route>]
  -c, --config-file=<configFile>
                        Config file
  -p, --port=<port>     API server port
  -r, --route=<route>   Route home

Simple REST API server test

$ java -jar target/synbag-0.0.1.jar

## Query
$ curl -X POST --data-urlencode "query=select * from user" 127.0.0.1:5280/q
{"rowCount":2,"rows":[{"dttm":"2021-07-26 13:29:51.644552","name":"abcde-name0","userid":"abcde0"},{"dttm":"2021-07-26 13:29:51.647925","name":"abcde-name1","userid":"abcde1"}]}

## INSERT
$ curl -X POST -d '{type=INS, extra={value={ver=4,info=v.4}}}' 127.0.0.1:5280/t/config

## UPDATE
$ curl -X POST -d '{type=UPD, extra={value={info=v.5}, where={ver=4}}}' 127.0.0.1:5280/t/config

## DELETE
$ curl -X POST -d '{type=DEL, extra={where={ver=4}}}' 127.0.0.1:5280/t/config

## GET
$ curl -X POST -d '{type=GET, extra={where={userid=abcde51}}}' 127.0.0.1:5280/t/user

## GET ALL
$ curl -X POST -d '{type=GET}' 127.0.0.1:5280/t/user 

## GET with extra options
$ curl -X POST -d '{type=GET, extra={orderBy="name desc"}}' 127.0.0.1:5280/t/user
$ curl -X POST -d '{type=GET, extra={orderBy="name desc", limit=10}}' 127.0.0.1:5280/t/user
$ curl -X POST -d '{type=GET, extra={orderBy="name desc", limit=10, offset=5}}' 127.0.0.1:5280/t/user 
$ curl -X POST -d '{type=GET, extra={orderBy="name desc", clause="name like \"%abcde-name8%\""}}' 127.0.0.1:5280/t/user

Still developping.. Enjoy.

synbag's People

Contributors

gywndi avatar

Watchers

 avatar  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.