Skip to content

Commit 9edd1d4

Browse files
committed
add example of O.Unique
1 parent d95f399 commit 9edd1d4

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/pages/5-data_modelling.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,12 +1170,13 @@ namely `O.PrimaryKey` and `O.AutoInc`.
11701170
Column options are defined in [`ColumnOption`][link-slick-column-options],
11711171
and as you have seen are accessed via `O`.
11721172

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`.
11751175

11761176
```tut:book
11771177
case class PhotoUser(
11781178
name : String,
1179+
email : String,
11791180
avatar : Option[Array[Byte]] = None,
11801181
id : Long = 0L)
11811182
@@ -1188,13 +1189,15 @@ class PhotoTable(tag: Tag) extends Table[PhotoUser](tag, "user") {
11881189
O.Default("Anonymous Coward")
11891190
)
11901191
1192+
def email = column[String]("email", O.Unique)
1193+
11911194
def avatar = column[Option[Array[Byte]]]("avatar", O.SqlType("BINARY(2048)"))
11921195
1193-
def * = (name, avatar, id).mapTo[PhotoUser]
1196+
def * = (name, email, avatar, id).mapTo[PhotoUser]
11941197
}
11951198
```
11961199

1197-
In this example we've done three things:
1200+
In this example we've done four things:
11981201

11991202
1. We've used `O.Length` to give the `name` column a maximum length.
12001203
This modifies the type of the column in the DDL statement.
@@ -1206,9 +1209,10 @@ In this example we've done three things:
12061209
2. We've used `O.Default` to give the `name` column a default value.
12071210
This adds a `DEFAULT` clause to the column definition in the DDL statement.
12081211

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.
12111213

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.
12121216

12131217

12141218
## Custom Column Mappings

0 commit comments

Comments
 (0)