Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Jan 28, 2022
1 parent 52614ba commit 63aa7f8
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Gorm Sharding

[![Go](https://github.com/go-gorm/sharding/actions/workflows/go.yml/badge.svg)](https://github.com/go-gorm/sharding/actions/workflows/go.yml)
[![Go](https://github.com/go-gorm/sharding/actions/workflows/tests.yml/badge.svg)](https://github.com/go-gorm/sharding/actions/workflows/tests.yml)

Gorm Sharding plugin using SQL parser and replace for splits large tables into smaller ones, redirects Query into sharding tables. Give you a high performance database access.

Expand All @@ -12,7 +12,7 @@ Gorm Sharding 是一个高性能的数据库分表中间件。

- Non-intrusive design. Load the plugin, specify the config, and all done.
- Lighting-fast. No network based middlewares, as fast as Go.
- Multiple database support. PostgreSQL tested, MySQL and SQLite is coming.
- Multiple database (PostgreSQL, MySQL) support.
- Integrated primary key generator (Snowflake, PostgreSQL Sequence, Custom, ...).

## Sharding process
Expand All @@ -29,16 +29,19 @@ go get -u gorm.io/sharding

## Usage

Open a db session.
Config the sharding middleware, register the tables which you want to shard.

```go
dsn := "postgres://localhost:5432/sharding-db?sslmode=disable"
db, err := gorm.Open(postgres.New(postgres.Config{DSN: dsn}))
```
import (
"fmt"

Config the sharding middleware, register the tables which you want to shard. See [Godoc](https://pkg.go.dev/github.com/go-gorm/sharding) for config details.
"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/sharding"
)

db, err := gorm.Open(postgres.New(postgres.Config{DSN: "postgres://localhost:5432/sharding-db?sslmode=disable"))

```go
db.Use(sharding.Register(sharding.Config{
ShardingKey: "user_id",
NumberOfShards: 64,
Expand Down

0 comments on commit 63aa7f8

Please sign in to comment.