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

database/gdb: Any support for sqlx like NamedQuery and NamedExec ? #3865

Open
RyoJerryYu opened this issue Oct 18, 2024 · 8 comments
Open

database/gdb: Any support for sqlx like NamedQuery and NamedExec ? #3865

RyoJerryYu opened this issue Oct 18, 2024 · 8 comments
Labels
feature help wanted planned This issue/proposal is planned into our next steps.

Comments

@RyoJerryYu
Copy link

What do you want to ask?

Using sqlx , we can exec an SQL like this:

type Task struct {
	ID     int64  `db:"id"`
	UserID string `db:"user_id"`
	Name   string       `db:"name"`
	Status proto.Status `db:"status"`
	CreateTime int64 `db:"timestamp"`
}

//...

result, err := db.NamedExec("INSERT INTO tasks (user_id,  status,timestamp) VALUES (:user_id, :status, :timestamp)", task)

Any similar alternative method to do this, just like DB.GetOne in GoFrame play well as an alternative to DB.Get in sqlx ?

In addition:

We do not intent to adapt into GoFrame's orm models, because there are too much works to do in our existing project.

@freesme
Copy link
Contributor

freesme commented Oct 18, 2024

你是在找这个吗?数据写入/保存方法需要结合Data方法使用,方法的参数类型可以为Map/Struct/Slice

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Are you looking for this? The data writing/saving method needs to be used in conjunction with the Data method. The parameter type of the method can be [Map/Struct/Slice](https://goframe.org/pages/viewpage.action?pageId=1114344#:~:text=% E6%95%B0%E6%8D%AE%E5%8F%82%E6%95%B0%E4%B9%9F%E5%B8%B8%E7%94%A8%20struct%20%E7%B1% BB%E5%9E%8B%EF%BC%8C%E4%BE%8B%E5%A6%82%E5%BD%93%E8%A1%A8%E5%AD%97%E6%AE%B5% E4%B8%BA%20uid/name/site%20%E6%97%B6%EF%BC%9A)

@freesme
Copy link
Contributor

freesme commented Oct 18, 2024

@RyoJerryYu
Copy link
Author

你是在找这个吗?数据写入/保存方法需要结合Data方法使用,方法的参数类型可以为Map/Struct/Slice

不是的,我们在考察将我们的旧代码移植到 GoFrame 的难度。我们不打算使用 ORM Feature ,必须要求是能像 sqlx 一样能直接接收 SQL 语句,因为我们的代码里有大量现成的 SQL 语句。

上面举出的只是一个简单例子,意图在于展示 NamedExec 方法的参数,不意味着我们只用 INSERT 语句。实际的 SQL 更复杂且多样,无法使用 Data 方法,那样迁移成本太高。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Are you looking for this? The data writing/saving method needs to be used in conjunction with the Data method. The parameter type of the method can be [Map/Struct/Slice](https://goframe.org/pages/viewpage.action?pageId=1114344#:~:text=% E6%95%B0%E6%8D%AE%E5%8F%82%E6%95%B0%E4%B9%9F%E5%B8%B8%E7%94%A8%20struct%20%E7%B1% BB%E5%9E%8B%EF%BC%8C%E4%BE%8B%E5%A6%82%E5%BD%93%E8%A1%A8%E5%AD%97%E6%AE%B5% E4%B8%BA%20uid/name/site%20%E6%97%B6%EF%BC%9A)

No, we are looking at the difficulty of porting our legacy code to GoFrame. We do not plan to use the ORM Feature, which must be able to directly receive SQL statements like sqlx, because there are a large number of ready-made SQL statements in our code.

The above example is just a simple example, the purpose is to show the parameters of the NamedExec method, it does not mean that we only use the INSERT statement. The actual SQL is more complex and diverse, and the Data method cannot be used, as the migration cost would be too high.

@gqcn
Copy link
Member

gqcn commented Oct 20, 2024

@RyoJerryYu Hello,ORM的原生SQL执行方法在这里 https://goframe.org/pages/viewpage.action?pageId=1114177 ,但是并不支持这种带命名变量占位符替换的功能,但我们会考虑支持,也欢迎大家一起来建设。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@RyoJerryYu Hello, the ORM's native SQL execution method is here https://goframe.org/pages/viewpage.action?pageId=1114177, but it does not support this function of replacing named variable placeholders, but we will consider it. Support and welcome everyone to build together.

@gqcn gqcn added feature help wanted planned This issue/proposal is planned into our next steps. and removed question labels Oct 20, 2024
Copy link

Hello @RyoJerryYu. We like your proposal/feedback and would appreciate a contribution via a Pull Request by you or another community member. We thank you in advance for your contribution and are looking forward to reviewing it!
你好 @RyoJerryYu。我们喜欢您的提案/反馈,并希望您或其他社区成员通过拉取请求做出贡献。我们提前感谢您的贡献,并期待对其进行审查。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature help wanted planned This issue/proposal is planned into our next steps.
Projects
None yet
Development

No branches or pull requests

4 participants