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

Add rendering to SQL for core data types #8

Closed
jdegoes opened this issue May 19, 2020 · 5 comments
Closed

Add rendering to SQL for core data types #8

jdegoes opened this issue May 19, 2020 · 5 comments

Comments

@jdegoes
Copy link
Member

jdegoes commented May 19, 2020

We should add rendering to SQL for core data types, with several options:

sealed trait RenderMode
object RenderMode {
  case object Compact
  final case class Pretty(indent: Int)
}
...

// On all SQL types
def render(mode: RenderMode): String = /* calls render builder */

private[zio] def renderBuilder(builder: StringBuilder: mode: RenderMode): Unit

The use of StringBuilder is for performance reasons and can be hidden as a private implementation detail.

Note that extreme care should be taken when rendering strings into SQL, as they must be properly escaped, to avoid SQL injection attacks.

@bertlebee
Copy link
Contributor

I'll give this one a go

@jdegoes
Copy link
Member Author

jdegoes commented May 19, 2020

Wow, that's awesome. Good luck and let me know if you need any help!

@bertlebee
Copy link
Contributor

I'll finish watching the video before I do too much on this. is the intention to return PreparedStatements at the top level? I'd think ideally we don't execute queries that aren't parameterised.

@jdegoes
Copy link
Member Author

jdegoes commented May 20, 2020

I would aim for a simple string rendering. Currently we don't have parameterized queries, which would be necessary to generate PreparedStatement. Also I think the core of the library should be usable without JDBC or even on Javascript.

We could consider this string rendering a step toward JDBC and also extremely useful for diagnostics / debugging / development.

@jczuchnowski
Copy link
Member

Closing this. @robmwalsh did a lot of work here. The rendering is now database specific.

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

3 participants