Skip to content

Commit 7dcd871

Browse files
committed
Java:完善 ShardingSphere Demo 分库分表的 字段及规则表达式
1 parent 792acb7 commit 7dcd871

File tree

9 files changed

+61
-26
lines changed

9 files changed

+61
-26
lines changed

APIJSON-Java-Server/APIJSONDemo-ShardingSphere/MySQL/ds_1_single/ds_1_Comment_0.sql

+2-2
Large diffs are not rendered by default.

APIJSON-Java-Server/APIJSONDemo-ShardingSphere/MySQL/ds_1_single/ds_1_Comment_1.sql

+2-2
Large diffs are not rendered by default.

APIJSON-Java-Server/APIJSONDemo-ShardingSphere/MySQL/ds_1_single/ds_1_Moment_0.sql

+3-3
Large diffs are not rendered by default.

APIJSON-Java-Server/APIJSONDemo-ShardingSphere/MySQL/ds_1_single/ds_1_Moment_1.sql

+3-3
Large diffs are not rendered by default.

APIJSON-Java-Server/APIJSONDemo-ShardingSphere/MySQL/ds_1_single/ds_1_apijson_user.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ UNLOCK TABLES;
5656
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
5757
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
5858

59-
-- Dump completed on 2025-02-03 23:27:31
59+
-- Dump completed on 2025-02-03 23:54:01

APIJSON-Java-Server/APIJSONDemo-ShardingSphere/MySQL/ds_2_single/ds_2_Comment_0.sql

+2-2
Large diffs are not rendered by default.

APIJSON-Java-Server/APIJSONDemo-ShardingSphere/MySQL/ds_2_single/ds_2_Comment_1.sql

+2-2
Large diffs are not rendered by default.

APIJSON-Java-Server/APIJSONDemo-ShardingSphere/MySQL/ds_2_single/ds_2_apijson_user.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ UNLOCK TABLES;
5656
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
5757
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
5858

59-
-- Dump completed on 2025-02-03 23:27:32
59+
-- Dump completed on 2025-02-03 23:54:02
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
rules:
2-
- !SHARDING
3-
tables: # Sharding table configuration
4-
apijson_user:
5-
actualDataNodes: ds-$->{0..1}.apijson_user # 分库 shading databases/schemas
6-
Moment: # Logic table name
7-
actualDataNodes: ds-0.Moment_$->{0..1} # 分表 shading tables
8-
Comment: # Logic table name
9-
actualDataNodes: ds-$->{0..1}.Comment_$->{0..1} # 分库*分表 shading both databases/schemas and tables
101
dataSources:
112
ds-0:
123
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
@@ -19,4 +10,48 @@ dataSources:
1910
driverClassName: com.mysql.jdbc.Driver
2011
jdbcUrl: jdbc:mysql://localhost:3306/ds_2?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8
2112
username: root
22-
password: apijson
13+
password: apijson
14+
15+
rules:
16+
- !SHARDING
17+
tables: # Sharding table configuration
18+
apijson_user:
19+
actualDataNodes: ds-$->{0..1}.apijson_user # 分库 shading databases/schemas
20+
databaseStrategy:
21+
standard:
22+
shardingColumn: id
23+
shardingAlgorithmName: user-sharding-ds
24+
Moment: # Logic table name
25+
actualDataNodes: ds-0.Moment_$->{0..1} # 分表 shading tables
26+
tableStrategy:
27+
standard:
28+
shardingColumn: userId
29+
shardingAlgorithmName: moment-sharding-table
30+
Comment: # Logic table name
31+
actualDataNodes: ds-$->{0..1}.Comment_$->{0..1} # 分库*分表 shading both databases/schemas and tables
32+
databaseStrategy:
33+
standard:
34+
shardingColumn: userId
35+
shardingAlgorithmName: comment-sharding-ds
36+
tableStrategy:
37+
standard:
38+
shardingColumn: momentId
39+
shardingAlgorithmName: comment-sharding-table
40+
41+
shardingAlgorithms:
42+
user-sharding-ds:
43+
type: INLINE
44+
props:
45+
algorithm-expression: ds-${id % 2}
46+
moment-sharding-table:
47+
type: INLINE
48+
props:
49+
algorithm-expression: Moment_${userId % 2}
50+
comment-sharding-ds:
51+
type: INLINE
52+
props:
53+
algorithm-expression: ds-${userId % 2}
54+
comment-sharding-table:
55+
type: INLINE
56+
props:
57+
algorithm-expression: Comment_${momentId % 2}

0 commit comments

Comments
 (0)