Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug TiDB Documentation: 使用 GORM 连接到 TiDB #15780

Closed
Tracked by #15772
qiancai opened this issue Dec 16, 2023 · 9 comments
Closed
Tracked by #15772

Debug TiDB Documentation: 使用 GORM 连接到 TiDB #15780

qiancai opened this issue Dec 16, 2023 · 9 comments
Assignees
Labels
2024-tidb-docs-dash This issue or PR is included in the 2024 TiDB Docs Dash event.

Comments

@qiancai
Copy link
Collaborator

qiancai commented Dec 16, 2023

此 issue 为 Debug TiDB Documentation: TiDB 中文文档测试说明・Issue #15772・pingcap/docs-cn 的 sub-issue,目的是为了测试和验证使用 GORM 连接到 TiDB 文档。

请参考 #15772 中的说明测试该文档。

  1. 在完成文档验证后,将您的验证结果以评论的形式添加到当前 issue 上。验证结果可以是您遇到的问题、发现的错误或其他任何发现。如果验证顺利通过,您也可以添加评论说明。
  2. 对于在验证过程中发现的任何问题或错误,欢迎创建 Pull Request(PR)直接修正文档。创建 PR 时,请在 PR 描述中指明该 PR 解决了哪个 issue (例如,Fix #15780)。关于如何创建 PR 的详情,请参考TiDB 中文文档贡献指南

非常感谢您对测试和验证文档的贡献!

@cool-wangtongzhou
Copy link

/assign

@cool-wangtongzhou
Copy link

cool-wangtongzhou commented Dec 30, 2023

使用gorm连接TiDB这个文档能够正常跑通,以下是我获取到的输出,你看一下是这个结果吗?

Image

@qiancai
Copy link
Collaborator Author

qiancai commented Jan 4, 2024

Sorry, I changed the assignee info by mistake. Let me reassign this issue.
/assign @cool-wangtongzhou

@qiancai
Copy link
Collaborator Author

qiancai commented Jan 4, 2024

使用 gorm 连接 TiDB 这个文档能够正常跑通,以下是我获取到的输出,你看一下是这个结果吗?

Image

@Icemap PTAL. Thanks

@Icemap
Copy link
Member

Icemap commented Jan 4, 2024

@cool-wangtongzhou 这里截图是否完整呀?在输出 this trade will success 后,还应有以下输出:

buyGoods:
    => this trade will success

2023/08/25 14:50:34 /Users/cheese/sdk/go1.18rc1/pkg/mod/github.com/pingcap-inc/[email protected]/util/txn_gorm.go:29
[0.588ms] [rows:0] set @@tidb_txn_mode=pessimistic

2023/08/25 14:50:34 /Users/cheese/GolandProjects/tidb-golang-gorm-quickstart/gorm.go:137
[1.448ms] [rows:1] SELECT * FROM `player` WHERE id = '2' FOR UPDATE

2023/08/25 14:50:34 /Users/cheese/GolandProjects/tidb-golang-gorm-quickstart/gorm.go:146
[1.341ms] [rows:1] SELECT * FROM `player` WHERE id = '1' FOR UPDATE

2023/08/25 14:50:34 /Users/cheese/GolandProjects/tidb-golang-gorm-quickstart/gorm.go:155
[5.877ms] [rows:1] UPDATE player set goods = goods + -2, coins = coins + 100 WHERE id = '2'

2023/08/25 14:50:34 /Users/cheese/GolandProjects/tidb-golang-gorm-quickstart/gorm.go:159
[1.535ms] [rows:1] UPDATE player set goods = goods + 2, coins = coins + -100 WHERE id = '1'

[buyGoods]:
    'trade success'

@rpaik
Copy link
Member

rpaik commented Jan 10, 2024

👋 @cool-wangtongzhou, just a quick reminder to make your TiDB Docs Dash contributions by January 12 at 07:59 UTC.

Let us know if you have any questions!

@cool-wangtongzhou
Copy link

@Icemap
是的,有这个输出。不好意思,之前没贴完整,以下是我得到的完整的运行结果。

(base) dns@SUNNY-MacBook-Air tidb-golang-gorm-quickstart % make
make build run
go build -o bin/gorm-example
./bin/gorm-example

2024/01/12 13:54:23 /Users/dns/workspace/tidb-golang-gorm-quickstart/gorm.go:48 SLOW SQL >= 200ms
[354.977ms] [rows:-] SELECT DATABASE()

2024/01/12 13:54:24 /Users/dns/workspace/tidb-golang-gorm-quickstart/gorm.go:48 SLOW SQL >= 200ms
[708.952ms] [rows:1] SELECT SCHEMA_NAME from Information_schema.SCHEMATA where SCHEMA_NAME LIKE 'test%' ORDER BY SCHEMA_NAME='test' DESC,SCHEMA_NAME limit 1

2024/01/12 13:54:24 /Users/dns/workspace/tidb-golang-gorm-quickstart/gorm.go:48 SLOW SQL >= 200ms
[715.825ms] [rows:-] SELECT count(*) FROM information_schema.tables WHERE table_schema = 'test' AND table_name = 'player' AND table_type = 'BASE TABLE'

2024/01/12 13:54:25 /Users/dns/workspace/tidb-golang-gorm-quickstart/gorm.go:48 SLOW SQL >= 200ms
[355.870ms] [rows:-] SELECT DATABASE()

2024/01/12 13:54:26 /Users/dns/workspace/tidb-golang-gorm-quickstart/gorm.go:48 SLOW SQL >= 200ms
[708.752ms] [rows:1] SELECT SCHEMA_NAME from Information_schema.SCHEMATA where SCHEMA_NAME LIKE 'test%' ORDER BY SCHEMA_NAME='test' DESC,SCHEMA_NAME limit 1

2024/01/12 13:54:26 /Users/dns/workspace/tidb-golang-gorm-quickstart/gorm.go:48 SLOW SQL >= 200ms
[422.213ms] [rows:-] SELECT * FROM `player` LIMIT 1

2024/01/12 13:54:27 /Users/dns/workspace/tidb-golang-gorm-quickstart/gorm.go:48 SLOW SQL >= 200ms
[717.316ms] [rows:-] SELECT column_name, column_default, is_nullable = 'YES', data_type, character_maximum_length, column_type, column_key, extra, column_comment, numeric_precision, numeric_scale , datetime_precision FROM information_schema.columns WHERE table_schema = 'test' AND table_name = 'player' ORDER BY ORDINAL_POSITION

2024/01/12 13:54:28 /Users/dns/workspace/tidb-golang-gorm-quickstart/gorm.go:84 SLOW SQL >= 200ms
[1434.618ms] [rows:0] INSERT INTO `player` (`id`,`coins`,`goods`) VALUES ('test',1,1) ON DUPLICATE KEY UPDATE `coins`=VALUES(`coins`),`goods`=VALUES(`goods`)

2024/01/12 13:54:29 /Users/dns/workspace/tidb-golang-gorm-quickstart/gorm.go:90 SLOW SQL >= 200ms
[718.369ms] [rows:1] SELECT * FROM `player` WHERE id = 'test'
getPlayer: {ID:test Coins:1 Goods:1}

2024/01/12 13:54:42 /Users/dns/workspace/tidb-golang-gorm-quickstart/gorm.go:111 SLOW SQL >= 200ms
[372.842ms] [rows:1] SELECT count(*) FROM `player`
countPlayers: 3841

2024/01/12 13:54:43 /Users/dns/workspace/tidb-golang-gorm-quickstart/gorm.go:116 SLOW SQL >= 200ms
[357.705ms] [rows:3] SELECT * FROM `player` LIMIT 3
print 1 player: {ID:00043b31-9496-47e3-a2d9-f200466ef6a5 Coins:2487 Goods:6476}
print 2 player: {ID:0006e910-a752-49ab-9283-4bc9a1923624 Coins:3405 Goods:2524}
print 3 player: {ID:00207f7b-3e45-484e-8bb2-97a09d86740a Coins:2427 Goods:4401}

2024/01/12 13:54:44 /Users/dns/workspace/tidb-golang-gorm-quickstart/gorm.go:64 SLOW SQL >= 200ms
[1541.777ms] [rows:2] INSERT INTO `player` (`id`,`coins`,`goods`) VALUES ('1',100,0) ON DUPLICATE KEY UPDATE `coins`=VALUES(`coins`),`goods`=VALUES(`goods`)

2024/01/12 13:54:46 /Users/dns/workspace/tidb-golang-gorm-quickstart/gorm.go:65 SLOW SQL >= 200ms
[1459.835ms] [rows:2] INSERT INTO `player` (`id`,`coins`,`goods`) VALUES ('2',114514,20) ON DUPLICATE KEY UPDATE `coins`=VALUES(`coins`),`goods`=VALUES(`goods`)

buyGoods:
    => this trade will fail

2024/01/12 13:54:46 /Users/dns/go/pkg/mod/github.com/pingcap-inc/[email protected]/util/txn_gorm.go:29 SLOW SQL >= 200ms
[358.948ms] [rows:0] set @@tidb_txn_mode=pessimistic

2024/01/12 13:54:47 /Users/dns/workspace/tidb-golang-gorm-quickstart/gorm.go:137 SLOW SQL >= 200ms
[712.693ms] [rows:1] SELECT * FROM `player` WHERE id = '2' FOR UPDATE

2024/01/12 13:54:48 /Users/dns/workspace/tidb-golang-gorm-quickstart/gorm.go:146 SLOW SQL >= 200ms
[718.327ms] [rows:1] SELECT * FROM `player` WHERE id = '1' FOR UPDATE

buyGoods:
    => this trade will success

2024/01/12 13:54:49 /Users/dns/go/pkg/mod/github.com/pingcap-inc/[email protected]/util/txn_gorm.go:29 SLOW SQL >= 200ms
[356.553ms] [rows:0] set @@tidb_txn_mode=pessimistic

2024/01/12 13:54:50 /Users/dns/workspace/tidb-golang-gorm-quickstart/gorm.go:137 SLOW SQL >= 200ms
[720.671ms] [rows:1] SELECT * FROM `player` WHERE id = '2' FOR UPDATE

2024/01/12 13:54:50 /Users/dns/workspace/tidb-golang-gorm-quickstart/gorm.go:146 SLOW SQL >= 200ms
[728.639ms] [rows:1] SELECT * FROM `player` WHERE id = '1' FOR UPDATE

2024/01/12 13:54:51 /Users/dns/workspace/tidb-golang-gorm-quickstart/gorm.go:155 SLOW SQL >= 200ms
[713.243ms] [rows:1] UPDATE player set goods = goods + -2, coins = coins + 100 WHERE id = '2'

2024/01/12 13:54:52 /Users/dns/workspace/tidb-golang-gorm-quickstart/gorm.go:159 SLOW SQL >= 200ms
[711.271ms] [rows:1] UPDATE player set goods = goods + 2, coins = coins + -100 WHERE id = '1'

[buyGoods]:
    'trade success'

@Icemap
Copy link
Member

Icemap commented Jan 12, 2024

是的,与预期一致。

@qiancai
Copy link
Collaborator Author

qiancai commented Jan 12, 2024

@cool-wangtongzhou, 非常感谢您对 使用 GORM 连接到 TiDB 文档的测试❤️。因为文档测试结果与预期一致,我们将关闭此 issue。如果后续您再遇到任何文档问题,欢迎在此文档仓库提 issue 或者 PR 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2024-tidb-docs-dash This issue or PR is included in the 2024 TiDB Docs Dash event.
Development

No branches or pull requests

4 participants