当前位置:网站首页>Simply use golang SQLC to generate MySQL query code
Simply use golang SQLC to generate MySQL query code
2022-07-24 10:19:00 【Not Lao Wang who lives next door】
Use sqlc The library can put sql Query code is generated directly golang Method calls directly , Improving the query speed can effectively avoid sql Error in query code .
The environment of this article windows, The database for mysql database .
install
1、 because slqc stay windows It cannot be used under the platform , So I am win10 Upper use docker To operate .
2、sqlc library GitHub Address :
https://github.com/kyleconroy/sqlc
Official document address :
https://docs.sqlc.dev/en/stable/tutorials/getting-started-mysql.html
3、docker Installation command :
docker pull kjconroy/sqlc
Easy to use
1、 Initialize build yaml The configuration file .
command :
docker run --rm -v "%cd%:/src" -w /src kjconroy/sqlc init
take "%cd%" Change to your own project directory
Example :
docker run --rm -v "d:\ProgramPro\workspace\go\test:/src" -w /src kjconroy/sqlc init
2、 Writing configuration files :
version: 1
packages:
- path: "./db/sqlc"
name: "tutorial"
engine: "mysql"
schema: "./db/migration"
queries: "./db/query"
path: The storage path of the output query file
engine: Database name , At present, we support postgres and mysql
queries:sql Query statement storage path
schema: Migration file storage directory
3、 To write sql file 
4、 function sqlc Generate the corresponding query file
docker run --rm -v "%cd%:/src" -w /src kjconroy/sqlc generate
Example :
docker run --rm -v "d:\ProgramPro\workspace\go\test:/src" -w /src kjconroy/sqlc generate
If it runs successfully, it means written sql The statement is correct
边栏推荐
- note: expected ‘void * (***)(void ***)’ but argument is of type ‘void (*)(void *)’
- Query about operating system security patch information
- 2022, enterprise informatization construction based on Unified Process Platform refers to thubierv0.1
- [sword finger offer II 115. reconstruction sequence]
- The best time to buy and sell stocks Ⅲ (leetcode-123)
- Configuration description and componentization development steps of various documents in the scaffold
- 图像处理:浮点数转定点数
- Differential restraint system -- 1 and 2 -- May 27, 2022
- Tag the specified commit and submit the tag
- Scaffold document directory description and document exposure
猜你喜欢

When the hot tea is out of stock, what does the new tea drink rely on to continue its life?

zoj1137+作业1--2022年5月28日

Raspberry Pie:: no space left on device
![[STM32 learning] (18) STM32 realizes LCD12864 display - parallel implementation of 8-bit bus](/img/6b/b49b9e7fff62026a4818561d79fe3f.png)
[STM32 learning] (18) STM32 realizes LCD12864 display - parallel implementation of 8-bit bus
![[STM32 learning] (16) STM32 realizes LCD1602 display (74HC595 drive) - 4-bit bus](/img/8f/19b0eb959d2b3f896c8e99f8e673d1.png)
[STM32 learning] (16) STM32 realizes LCD1602 display (74HC595 drive) - 4-bit bus
![[STM32 learning] (14) two 74HC595 controls four nixie tube displays](/img/22/c83e29bead8e6298a0a3564419022c.png)
[STM32 learning] (14) two 74HC595 controls four nixie tube displays
![[STM32 learning] (7) use of serial port 2 (usart2)](/img/e8/7a01cb2753f448d745e0d8712b3ebc.png)
[STM32 learning] (7) use of serial port 2 (usart2)

The best time to buy and sell stocks (leetcode-121)

【机器人学习】机构运动学分析与matlab仿真(三维模型+word报告+matlab程序)

WEB安全基础 - - -文件上传(文件上传绕过)
随机推荐
Ask you to build a small program server
Analysis of Kube proxy IPVS mode
When the hot tea is out of stock, what does the new tea drink rely on to continue its life?
【剑指 Offer II 115. 重建序列】
Arduino drive Lora module node
How does ribbon get the default zoneawareloadbalancer?
[STM32 learning] (11) STM32 Mifare_ Use of one (S50) m1s50 (read, write, key modification, control bit interpretation)
Implementation and traversal of binary tree and binary tree sorting tree
zoj 2770 差分约束系统---2--2022年5月20日
TypeError: Object of type ‘int32‘ is not JSON serializable
error: field ‘XXX’ declared as a function
Taurus. How to upgrade and run MVC on net6 and net7
ffmpeg花屏解决(修改源码,丢弃不完整帧)
MySQL——锁
Arduino drive lcd1602a
Deployment and analysis of coredns
In the envy of LETV, there is a "meaning crisis" of contemporary workers
Add a love power logo to your website
Analysis of distributed lock redistribution principle
Association Rules -- July 10, 2022