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

Request Feature - ToSQL on struct_insert.go #47

Closed
raxisau opened this issue Apr 22, 2020 · 3 comments
Closed

Request Feature - ToSQL on struct_insert.go #47

raxisau opened this issue Apr 22, 2020 · 3 comments

Comments

@raxisau
Copy link

raxisau commented Apr 22, 2020

Gi. Can I request that the following is added to struct_insert.go

// ToSQL returns a string with the SQL statement (containing placeholders),
// the arguments slices, and an error.
func (si *StructInsert) ToSQL() (string, []interface{}, error) {
	a, b, c := si.insertStatement.ToSQL()
	return a, b, c
}

@samonzeweb
Copy link
Owner

Hi,

There is no ToSQL function in struct_insert.go, nor struct_select, ... because the purpose of these tools are not to build queries, but to ease structs persistence.

To build queries (either to execute them or just get the SQL code) you can use non-struct insert code : https://github.com/samonzeweb/godb/blob/master/insert_statement.go . There is no reason it does not the job, because stuct insertion use this code under the hood.

Or perhaps there is another thing you want to achieve I didn't see. Let me now if needed.

@raxisau
Copy link
Author

raxisau commented Apr 24, 2020

No Problems.

My request was to display SQL that is being implemented. It is more for Debug and tuning purposes.

@samonzeweb
Copy link
Owner

You can use a logger. All SQL queries are logged, you can dump then to stdout, stderr, a file, ... and as it's optional you can enable/disable the feature as you want/need.

See the README :

	// OPTIONAL: Set logger to show SQL execution logs
	db.SetLogger(log.New(os.Stderr, "", 0))

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

No branches or pull requests

2 participants