upper / db

Data Access Layer (DAL) for PostgreSQL, CockroachDB, MySQL, SQLite and MongoDB with ORM-like features.
https://upper.io/
MIT License
3.53k stars 234 forks source link

Insert and Save Queries incompatible with postgres default values (v3) #604

Open kipply opened 3 years ago

kipply commented 3 years ago

An insert or save query (that goes to an insert) will pass through all columns, and using a null value if that column had no input.

This causes failures with postgres in the form of either;

  1. the column that has a default is set to nil
  2. the column that has a default yields an error because it has a not null clause that should be protected by a default

will test with upper v4 soon

xiam commented 3 years ago

Hello @kipply,

Is this case something that could be solved by using the omitempty option? That word tells upper to ignore the field when it has a zero value:

type User struct {
  ID int `db:"id,omitempty"`
}

Let me know if your case is different.