yahoo / squidb

SquiDB is a SQLite database library for Android and iOS
https://github.com/yahoo/squidb/wiki
Apache License 2.0
1.31k stars 132 forks source link

Typesafe column default annotations [4.0] #272

Closed sbosley closed 7 years ago

sbosley commented 7 years ago

The main focus of this PR is to introduce typesafe default value annotations for table model specs that replace the now-removed @ColumnSpec(defaultValue = "?"). There are annotations for each primitive type (@DefaultLong, @DefaultString, etc.), as well as an explicit @DefaultNull and @DefaultExpression for specifying defaults as SQL expressions (in particular adding support for the special cases like CURRENT_TIMESTAMP). In addition to the annotations themselves only accepting a value of the correct type, we also perform validation confirming that only the expected type is used when defining a column default (i.e. we can log an error if a long column is annotated with @DefaultString).

This PR also removes the @ColumnSpec(name = "colName") field in favor of a dedicated @ColumnName("colName") annotation. This is the first step in a larger effort to break apart the different kinds of column definition components into their own annotations, rather than having a single monolithic annotation like ColumnSpec that does too many different things. Currently, ColumnSpec still exists only for the constraints field, but I expect that to also be replaced by a dedicated annotation in a future change. Update: I realized I could finish this part off by simply renaming ColumnSpec, so I did. @ColumnSpec is now @ConstraintSql, which accepts a single SQL string argument to be appended to the column constraints.