golang sql mapper framework
source link: https://studygolang.com/articles/36168
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Juice 简介
juice 是一个基于 golang 的 sql mapper 框架,它的目标是提供一个简单易用的 sql mapper 框架,让开发者可以更专注于业务逻辑的开发。
如果你是一个 golang 开发者,或者你正在寻找一个简单易用的 sql mapper 框架,那么 juice 可能是你的不二之选。
http://github.com/eatmoreapple/juice
- 轻量级,高性能,无第三方依赖
- 简单易用,容易扩展
- 动态 sql 语句
- 支持多数据源
- 泛型结果集映射
- 自定义表达式
- 自定义函数
版本要求
- go 1.18+
go get -u github.com/eatmoreapple/juice
快速开始 编写sql mapper配置文件
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<environments default="prod">
<environment id="prod">
<dataSource>root:qwe123@tcp(localhost:3306)/database</dataSource>
<driver>mysql</driver>
</environment>
</environments>
<mappers>
<mapper namespace="main">
<select id="HelloWorld">
select "hello world" as message
</select>
</mapper>
</mappers>
</configuration>
注意:dataSource 的格式跟用 sql.Open() 函数的格式相同。
package main
import (
"fmt"
"github.com/eatmoreapple/juice"
_ "github.com/go-sql-driver/mysql"
)
func HelloWorld() {}
func main() {
cfg, err := juice.NewXMLConfiguration("config.xml")
if err != nil {
fmt.Println(err)
return
}
engine, err := juice.DefaultEngine(cfg)
if err != nil {
fmt.Println(err)
return
}
message, err := juice.NewGenericManager[string](engine).Object(HelloWorld).Query(nil)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(message)
}
注意:虽然 juice 不依赖第三方库,但是它需要依赖数据库驱动,所以在使用 juice 之前,你需要先安装数据库驱动,比如要使用mysql, 那么你需要先安装 github.com/go-sql-driver/mysql
如果运行报错,那么可能是因为你的数据库没有启动,或者你的数据库配置有误,检查一下数据库配置是否正确。
go run main.go
[juice] 2022/11/05 19:56:49 [main.HelloWorld] select "hello world" as message [] 5.3138ms
hello world
Recommend
-
120
MyBatis SQL Mapper Framework for Java
-
88
Zia Mapper Photo Manager Beta Available for Testing Capture and document job site photos easier with Zia Mapper Photo Manager. Now in Beta, this app works on standard Android and iOS mobile devices and saves you time when sorting and preparing p...
-
32
-
37
提到看源码,很多同学内心的恐惧的,其实这个从人性的角度来说是非常正常的,因为人们对未知的事物,都是非常恐惧的,其次,你内心可能始终觉得,好像不会原理也还是能工作啊,你的潜意识里没有强烈的欲望.从阅读源码的经历来说,Java三大框架SSM中...
-
55
title: 玩转spring-boot-mybatis date: 2019-03-11 19:36:57 type: "mybatis" categories: mybatis #分类名 tags: mybatis --- 作为持久层的ORM框架,目前在国内主流之一就是MyBat...
-
12
README.md MyBatis 通用 Mapper4
-
21
README.md vim-leader-mapper Introduction Vim-Leader-Mapper is a Neovim plugin to create leader key mapping and a visual menu to disp...
-
55
hello~各位读者好,我是鸭血粉丝(大家可以称呼我为「阿粉」)。今天,阿粉带着大家来了解一下 mybatis 接口的创建。 1.上期回顾 首先,我们还是回顾一下上篇文件的类容。先看下这个测试类,大家还有...
-
35
动态代理的功能:通过拦截器方法回调,对目标target方法进行增强。言外之意就是为了增强目标target方法。上面这句话没错,但也不要认为它就是真理,殊不知,动态代理还有投鞭断流的霸权,连目标target都不要的科幻模式。注:本文默认认为,读者对动态代理的原理是...
-
14
pmem.ioPersistent Memory Programming Using Persistent Memory Devices with the Linux Device Mapper...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK