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

verify Inserts with macro #806

Merged
merged 4 commits into from
Jan 15, 2023
Merged

verify Inserts with macro #806

merged 4 commits into from
Jan 15, 2023

Conversation

sviezypan
Copy link
Collaborator

This PR deletes the insertUtils.scala class which was based on implicits and non scalable 22 arities of tuples and case classes.

PR introduces insertlike.scala macro which provides very nice error messages for inserts. Also the memory problem by sbt fmt is gone.

Example 1:


      insertInto(customers)(
        customerId,
        fName
      ).values((UUID.randomUUID(), "Jaro"))

yields error

You need to insert to all non nullable columns. 
Null value in columns 'String("createdTimestamp") and String("lastName") and String("createdTimestampString") and String("verified") and String("dob")' violates not-null constraint

Example 2:

insertInto(orderDetails)(orderDetailsOrderId, orderDetailsProductId, quantity, unitPrice)
        .values((UUID.randomUUID(), UUID.randomUUID(), BigDecimal.valueOf(11.00), 4))

fails with

Order of types of columns don't match the inserted values. 
Column types: java.util.UUID, java.util.UUID, Int, java.math.BigDecimal
Inserted types: java.util.UUID, java.util.UUID, java.math.BigDecimal, Int

Example 3:

insertInto(orderDetails)(orderDetailsOrderId, orderDetailsProductId, quantity, unitPrice)
        .values((UUID.randomUUID(), UUID.randomUUID(), BigDecimal.valueOf(11.00)))

fails with INSERT has more target columns than expressions

@sviezypan sviezypan requested a review from a team as a code owner January 15, 2023 13:56
@sviezypan sviezypan merged commit 5b8c88f into zio:master Jan 15, 2023
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

Successfully merging this pull request may close these issues.

2 participants