# juice **Repository Path**: eatmoreapple/juice ## Basic Information - **Project Name**: juice - **Description**: SQL mapper framework for Golang - **Primary Language**: Go - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2022-11-06 - **Last Updated**: 2026-05-15 ## Categories & Tags **Categories**: database-dev **Tags**: None ## README

Juice Logo

## Juice: A SQL Mapper for Go Inspired by MyBatis [![Go Doc](https://pkg.go.dev/badge/github.com/go-juicedev/juice)](https://pkg.go.dev/github.com/go-juicedev/juice) [![Release](https://img.shields.io/github/v/release/eatmoreapple/juice.svg?style=flat-square)](https://github.com/go-juicedev/juice/releases) ![Go Report Card](https://goreportcard.com/badge/github.com/go-juicedev/juice) ![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg) [![JetBrains Marketplace](https://img.shields.io/jetbrains/plugin/v/26401-juice.svg)](https://plugins.jetbrains.com/plugin/26401-juice) [![JetBrains Marketplace Downloads](https://img.shields.io/jetbrains/plugin/d/26401-juice.svg)](https://plugins.jetbrains.com/plugin/26401-juice) Juice is a SQL mapper for Go that keeps SQL explicit while adding XML mappers, dynamic SQL, typed binding, middleware, and transaction helpers. - [Why Juice](#why-juice) - [Quick Start](#quick-start) - [Installation](#installation) - [When To Use](#when-to-use) - [Documentation](#documentation) - [License](#license) - [Support Me](#support-me) ### Why Juice - Keep SQL readable and explicit instead of hiding it behind a heavy ORM - Organize queries with XML mappers inspired by MyBatis - Build dynamic SQL with nodes like `if`, `where`, `set`, and `foreach` - Bind query results into typed Go values with generics - Extend execution with middleware, transaction helpers, and datasource switching ### Quick Start Create a minimal configuration: ```xml sqlite.db sqlite3 ``` Define a mapper: ```xml ``` Call it from Go: ```go package main import ( "context" "fmt" "github.com/go-juicedev/juice" _ "github.com/mattn/go-sqlite3" ) type Repository interface { HelloWorld(ctx context.Context) (string, error) } type RepositoryImpl struct { manager juice.Manager } func (r RepositoryImpl) HelloWorld(ctx context.Context) (string, error) { executor := juice.NewGenericManager[string](r.manager).Object(Repository(r).HelloWorld) return executor.QueryContext(ctx, nil) } func main() { cfg, err := juice.NewXMLConfiguration("config.xml") if err != nil { panic(err) } engine, err := juice.Default(cfg) if err != nil { panic(err) } defer engine.Close() repo := RepositoryImpl{manager: engine} result, err := repo.HelloWorld(context.Background()) fmt.Println(result, err) } ``` Run it: ```sh CGO_ENABLED=1 go run main.go ``` Expected output: ```text hello world ``` ### Installation Install Juice: ```sh go get github.com/go-juicedev/juice ``` Install a database driver for the backend you want to use. For example, the quick start above uses SQLite: ```go import _ "github.com/mattn/go-sqlite3" ``` If you use the SQLite example above, `CGO_ENABLED=1` is required. ### When To Use Juice is a good fit when: - you want explicit SQL instead of a code-first ORM - you like MyBatis-style mapper organization - you need dynamic SQL without manually concatenating strings - you want a thin abstraction over `database/sql` with stronger structure Juice may not be the right fit when: - you want a code-first query builder or ORM model layer - you do not want XML-based mapping at all - you expect built-in migration or schema management features ### Documentation - API Reference: - English Docs: - 简体中文文档: ### License Juice is licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for the full license text. ## Support Me If you like my work, please consider supporting me by buying me a coffee. Buy Me A Coffee