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

增加apply方法,用于拼接自定义sql字符串 #76

Open
PhoenixL0911 opened this issue Sep 15, 2023 · 4 comments
Open

增加apply方法,用于拼接自定义sql字符串 #76

PhoenixL0911 opened this issue Sep 15, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@PhoenixL0911
Copy link
Contributor

PhoenixL0911 commented Sep 15, 2023

需求案例场景:子查询、自定义sql片段
伪代码:

	var expectSql = "SELECT * FROM `Users` WHERE username = 'afumu' OR age = 20"
	sessionDb := checkSelectSql(t, expectSql)
	query, u := gplus.NewQuery[User]()
	query.Eq(&u.Username, "afumu").Or().Eq(&u.Age, 20).Apply("AND id IN (SELECT user_id FROM app_user)")
	gplus.SelectList[User](query, gplus.Db(sessionDb))
@PhoenixL0911
Copy link
Contributor Author

@afumu 目前所使用到的条件构造,仍有很大的不便,如:无法无法支持子句的构建,即便后续添加了apply,手写sql仍然是一个比较麻烦的事。感觉条件构造器这一块还有很大的优化空间,对于CRUD,应当分别提供不同的构造器。这一块感觉可以参考一下成熟的SQL构建库,如:go-sqlbuilder

@afumu
Copy link
Member

afumu commented Sep 15, 2023

如果CRUD都提供不同的构造器,感觉对于使用者来说有点麻烦了

@PhoenixL0911
Copy link
Contributor Author

如果CRUD都提供不同的构造器,感觉对于使用者来说有点麻烦了

增删改可以共用一个,单查询提供一个,增删改涉及的内容少,主要还是查询部分。

@icetech233
Copy link

如果CRUD都提供不同的构造器,感觉对于使用者来说有点麻烦了

增删改可以共用一个,单查询提供一个,增删改涉及的内容少,主要还是查询部分。

直接用gorm就好了, 就plus 就用个泛型的查询

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants