@@ -1170,12 +1170,13 @@ namely `O.PrimaryKey` and `O.AutoInc`.
1170
1170
Column options are defined in [ ` ColumnOption ` ] [ link-slick-column-options ] ,
1171
1171
and as you have seen are accessed via ` O ` .
1172
1172
1173
- The following example introduces three new options:
1174
- ` O.Length ` , ` O.SqlType ` , and ` O.Default ` .
1173
+ The following example introduces four new options:
1174
+ ` O.Length ` , ` O.SqlType ` , ` O.Unique ` , and ` O.Default ` .
1175
1175
1176
1176
``` tut:book
1177
1177
case class PhotoUser(
1178
1178
name : String,
1179
+ email : String,
1179
1180
avatar : Option[Array[Byte]] = None,
1180
1181
id : Long = 0L)
1181
1182
@@ -1188,13 +1189,15 @@ class PhotoTable(tag: Tag) extends Table[PhotoUser](tag, "user") {
1188
1189
O.Default("Anonymous Coward")
1189
1190
)
1190
1191
1192
+ def email = column[String]("email", O.Unique)
1193
+
1191
1194
def avatar = column[Option[Array[Byte]]]("avatar", O.SqlType("BINARY(2048)"))
1192
1195
1193
- def * = (name, avatar, id).mapTo[PhotoUser]
1196
+ def * = (name, email, avatar, id).mapTo[PhotoUser]
1194
1197
}
1195
1198
```
1196
1199
1197
- In this example we've done three things:
1200
+ In this example we've done four things:
1198
1201
1199
1202
1 . We've used ` O.Length ` to give the ` name ` column a maximum length.
1200
1203
This modifies the type of the column in the DDL statement.
@@ -1206,9 +1209,10 @@ In this example we've done three things:
1206
1209
2 . We've used ` O.Default ` to give the ` name ` column a default value.
1207
1210
This adds a ` DEFAULT ` clause to the column definition in the DDL statement.
1208
1211
1209
- 3 . We've used ` O.SqlType ` to control the exact type used by the database.
1210
- The values allowed here depend on the database we're using.
1212
+ 3 . We added a uniqueness constraint on the ` email ` column.
1211
1213
1214
+ 4 . We've used ` O.SqlType ` to control the exact type used by the database.
1215
+ The values allowed here depend on the database we're using.
1212
1216
1213
1217
1214
1218
## Custom Column Mappings
0 commit comments