zjcnb edited a comment on issue #11621:
URL:
https://github.com/apache/shardingsphere/issues/11621#issuecomment-893147114
Example for yml:
```
schemaName: logic_db
rules:
- !SHARDING
tables:
t_order:
actualDataNodes: jdbc_${0..1}.t_order_${0..1}
t_order_item:
actualDataNodes: jdbc_${0..1}.t_order_item_${0..1}
keyGenerateStrategy:
column: item_id
keyGeneratorName: increment
t_config:
actualDataNodes: jdbc_${0..1}.t_config
t_user:
actualDataNodes: jdbc_0.t_user_${0..1}
tableStrategy:
standard:
shardingColumn: id
shardingAlgorithmName: table_inline
keyGenerateStrategy:
column: id
keyGeneratorName: reset_increment
autoTables:
t_order_auto:
actualDataSources: jdbc_0, jdbc_1
shardingStrategy:
standard:
shardingColumn: order_id
shardingAlgorithmName: mod
t_order_item_auto:
shardingStrategy:
standard:
shardingColumn: order_id
shardingAlgorithmName: mod
bindingTables:
- t_order,t_order_item
broadcastTables:
- t_config
- t_sys
defaultTableStrategy:
standard:
shardingColumn: order_id
shardingAlgorithmName: standard_test
defaultDatabaseStrategy:
standard:
shardingColumn: user_id
shardingAlgorithmName: standard_test
shardingAlgorithms:
standard_test:
type: STANDARD_TEST
table_inline:
type: INLINE
props:
algorithm-expression: t_user_${id % 2}
mod:
type: MOD
props:
sharding-count: 2
keyGenerators:
increment:
type: INCREMENT
reset_increment:
type: RESET_INCREMENT
```
Example for properties:
```
spring.shardingsphere.schema.name=logic_db
spring.shardingsphere.datasource.names=ds-0,ds-1
spring.shardingsphere.datasource.ds-0.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
spring.shardingsphere.datasource.ds-0.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds-0.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.ds-0.username=root
spring.shardingsphere.datasource.ds-0.password=
spring.shardingsphere.datasource.ds-1.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
spring.shardingsphere.datasource.ds-1.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds-1.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.ds-1.username=root
spring.shardingsphere.datasource.ds-1.password=
spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-column=user_id
spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-algorithm-name=database-inline
spring.shardingsphere.rules.sharding.binding-tables=t_order,t_order_item
spring.shardingsphere.rules.sharding.broadcast-tables=t_address
spring.shardingsphere.rules.sharding.tables.t_order.actual-data-nodes=ds-$->{0..1}.t_order
spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.column=order_id
spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.key-generator-name=snowflake
spring.shardingsphere.rules.sharding.tables.t_order_item.actual-data-nodes=ds-$->{0..1}.t_order_item
spring.shardingsphere.rules.sharding.tables.t_order_item.key-generate-strategy.column=order_item_id
spring.shardingsphere.rules.sharding.tables.t_order_item.key-generate-strategy.key-generator-name=snowflake
spring.shardingsphere.rules.sharding.sharding-algorithms.database-inline.type=INLINE
spring.shardingsphere.rules.sharding.sharding-algorithms.database-inline.props.algorithm-expression=ds-$->{user_id
% 2}
spring.shardingsphere.rules.sharding.key-generators.snowflake.type=SNOWFLAKE
spring.shardingsphere.rules.sharding.key-generators.snowflake.props.worker-id=123
```
Example for namespace:
```
<bean id="demo_ds_0" class="com.zaxxer.hikari.HikariDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl"
value="jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>
<bean id="demo_ds_1" class="com.zaxxer.hikari.HikariDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl"
value="jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>
<sharding:standard-strategy id="databaseStrategy"
sharding-column="user_id" algorithm-ref="inlineStrategyShardingAlgorithm" />
<sharding:sharding-algorithm id="inlineStrategyShardingAlgorithm"
type="INLINE">
<props>
<prop key="algorithm-expression">demo_ds_${user_id % 2}</prop>
</props>
</sharding:sharding-algorithm>
<sharding:key-generate-algorithm id="snowflakeAlgorithm"
type="SNOWFLAKE">
<props>
<prop key="worker-id">123</prop>
</props>
</sharding:key-generate-algorithm>
<sharding:key-generate-strategy id="orderKeyGenerator" column="order_id"
algorithm-ref="snowflakeAlgorithm" />
<sharding:key-generate-strategy id="itemKeyGenerator"
column="order_item_id" algorithm-ref="snowflakeAlgorithm" />
<sharding:rule id="shardingRule">
<sharding:table-rules>
<sharding:table-rule logic-table="t_order"
database-strategy-ref="databaseStrategy"
key-generate-strategy-ref="orderKeyGenerator" />
<sharding:table-rule logic-table="t_order_item"
database-strategy-ref="databaseStrategy"
key-generate-strategy-ref="itemKeyGenerator" />
</sharding:table-rules>
<sharding:binding-table-rules>
<sharding:binding-table-rule
logic-tables="t_order,t_order_item"/>
</sharding:binding-table-rules>
<sharding:broadcast-table-rules>
<sharding:broadcast-table-rule table="t_address"/>
</sharding:broadcast-table-rules>
</sharding:rule>
<shardingsphere:data-source id="shardingDataSource"
data-source-names="demo_ds_0, demo_ds_1" rule-refs="shardingRule"
schema-name="logic_db" />
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]