Popularity
3.6
Growing
Activity
0.0
-
76
4
8

Programming language: Go
License: MIT License
Tags: Go Generate Tools    

sqlgen alternatives and similar packages

Based on the "Go Generate Tools" category.
Alternatively, view sqlgen alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of sqlgen or a related project?

Add another 'Go Generate Tools' Package

README

sqlgen

English | [中文](README_cn.md)

Go

sqlgen is a tool to generate bun, gorm, sql, sqlx and xorm sql code from SQL file which is inspired by

Installation

go install github.com/anqiansong/sqlgen@latest

Example

See example

Queries rule

1. Function Name

You can define a function via fn keyword in line comment, for example:

-- fn: my_func
SELECT * FROM user;

it will be generated as:

func (m *UserModel) my_func (...) {
    ...
}

2. Get One Record

The expression limit 1 must be explicitly defined if you want to get only one record, for example:

-- fn: FindOne
select * from user where id = ? limit 1;

3. Marker or Values?

For arguments of SQL, you can use ? or explicitly values to mark them, in sqlgen, the arguments will be converted into variables, for example, the following query are equivalent:

NOTES: It does not apply to rule 2

-- fn: FineLimit
select * from user where id = ?;

-- fn: FineLimit
select * from user where id = 1;

4. SQL Function

sqlgen supports aggregate function queries in sql, other than that, other functions are not supported so far. All the aggregate function query expressions must contain AS expression, for example:

-- fn: CountAll
select count(*) as count from user;

For most query cases, you can see example.sql for details.

How it works

  1. Create a SQL file
  2. Write your SQL code in the SQL file
  3. Run sqlgen to generate code

Notes

  1. Only support MYSQL code generation.
  2. Do not support multiple tables in one SQL file.
  3. Do not support join query.