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

support dynamic conditions, In the form of struct or map. #1061

Closed
Neightly opened this issue Nov 17, 2024 · 4 comments
Closed

support dynamic conditions, In the form of struct or map. #1061

Neightly opened this issue Nov 17, 2024 · 4 comments
Labels

Comments

@Neightly
Copy link

Bun's goal is to help you write idiomatic SQL, not to hide it behind awkward constructs.

It is good for static code, when table schemas are known at compile time.

What about dynamic tables created at runtime?
Unknown about table name and field name, how I can use Where family methods to construct conditions?

Field-based query conditions usually exist as a whole, so support for structs would be nice.

@j2gg0s
Copy link
Collaborator

j2gg0s commented Nov 18, 2024

Can you provide more specific use cases?

@Neightly
Copy link
Author

// dummy fields known at runtime
var Main1118 = func() *dynamic.DomainRepository {
	Main := dynamic.NewDomainRepository("test", "jux_main_1118", "main1118")
	Main.AddUint64("SystemId", dynamic.WithRaw(`json:"system_id" bun:"system_id"`))
	Main.AddString("TypeName", dynamic.WithRaw(`json:"typename" bun:"type_name"`))
	Main.AddInt32("RowIndex", dynamic.WithRaw(`json:"rowindex" bun:"row_index"`))
	Main.AddInt8("Status", dynamic.WithRaw(`json:"status" bun:"status"`))
	return Main
}()

// create table
_ = Main1118.CreateTable(db)

// cond and ptr both point the same value, cond for reflect, ptr for static
cond, ptr = Main1118.StructValue(map[string]any{
    // conditions are different each time.
    "SystemId": uint64(99), // "test"."jux_main_1118"."system_id" = 99
    "TypeName": "XXXX", // "test"."jux_main_1118"."type_name" = 'XXXX'
})
_, records, err := Main1118.Slice(db, cond, ptr)

@j2gg0s
Copy link
Collaborator

j2gg0s commented Nov 18, 2024

Thank you for the additional use cases.

But I am a supporter of static strong typing. Let’s see what other maintainers think.

Copy link

This issue has been automatically marked as stale because it has not had activity in the last 30 days. If there is no update within the next 7 days, this issue will be closed.

@github-actions github-actions bot added the stale label Dec 19, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants