@@ -213,7 +213,7 @@ type IndexAnnotation struct {
213213 //
214214 Desc bool
215215
216- // DescColumns defines the DESC clause for columns in a multi column index.
216+ // DescColumns defines the DESC clause for columns in multi- column index.
217217 // In MySQL, the following annotation maps to:
218218 //
219219 // index.Fields("c1", "c2", "c3").
@@ -225,6 +225,18 @@ type IndexAnnotation struct {
225225 //
226226 DescColumns map [string ]bool
227227
228+ // IncludeColumns defines the INCLUDE clause for the index.
229+ // Works only in Postgres and its definition is as follows:
230+ //
231+ // index.Fields("c1").
232+ // Annotation(
233+ // entsql.IncludeColumns("c2"),
234+ // )
235+ //
236+ // CREATE INDEX "table_column" ON "table"("c1") INCLUDE ("c2")
237+ //
238+ IncludeColumns []string
239+
228240 // Type defines the type of the index.
229241 // In MySQL, the following annotation maps to:
230242 //
@@ -257,7 +269,6 @@ type IndexAnnotation struct {
257269// Annotation(entsql.Prefix(100))
258270//
259271// CREATE INDEX `table_column` ON `table`(`column`(100))
260- //
261272func Prefix (prefix uint ) * IndexAnnotation {
262273 return & IndexAnnotation {
263274 Prefix : prefix ,
@@ -274,7 +285,6 @@ func Prefix(prefix uint) *IndexAnnotation {
274285// )
275286//
276287// CREATE INDEX `table_c1_c2_c3` ON `table`(`c1`(100), `c2`(200), `c3`)
277- //
278288func PrefixColumn (name string , prefix uint ) * IndexAnnotation {
279289 return & IndexAnnotation {
280290 PrefixColumns : map [string ]uint {
@@ -290,7 +300,6 @@ func PrefixColumn(name string, prefix uint) *IndexAnnotation {
290300// Annotation(entsql.Desc())
291301//
292302// CREATE INDEX `table_column` ON `table`(`column` DESC)
293- //
294303func Desc () * IndexAnnotation {
295304 return & IndexAnnotation {
296305 Desc : true ,
@@ -306,7 +315,6 @@ func Desc() *IndexAnnotation {
306315// )
307316//
308317// CREATE INDEX `table_c1_c2_c3` ON `table`(`c1` DESC, `c2` DESC, `c3`)
309- //
310318func DescColumns (names ... string ) * IndexAnnotation {
311319 ant := & IndexAnnotation {
312320 DescColumns : make (map [string ]bool , len (names )),
@@ -317,7 +325,20 @@ func DescColumns(names ...string) *IndexAnnotation {
317325 return ant
318326}
319327
320- // Type defines the type of the index.
328+ // IncludeColumns defines the INCLUDE clause for the index.
329+ // Works only in Postgres and its definition is as follows:
330+ //
331+ // index.Fields("c1").
332+ // Annotation(
333+ // entsql.IncludeColumns("c2"),
334+ // )
335+ //
336+ // CREATE INDEX "table_column" ON "table"("c1") INCLUDE ("c2")
337+ func IncludeColumns (names ... string ) * IndexAnnotation {
338+ return & IndexAnnotation {IncludeColumns : names }
339+ }
340+
341+ // IndexType defines the type of the index.
321342// In MySQL, the following annotation maps to:
322343//
323344// index.Fields("c1").
@@ -326,12 +347,11 @@ func DescColumns(names ...string) *IndexAnnotation {
326347// )
327348//
328349// CREATE FULLTEXT INDEX `table_c1` ON `table`(`c1`)
329- //
330350func IndexType (t string ) * IndexAnnotation {
331351 return & IndexAnnotation {Type : t }
332352}
333353
334- // Types is like the Type option but allows mapping an index-type per dialect.
354+ // IndexTypes is like the Type option but allows mapping an index-type per dialect.
335355//
336356// index.Fields("c1").
337357// Annotations(
@@ -340,7 +360,6 @@ func IndexType(t string) *IndexAnnotation {
340360// dialect.Postgres: "GIN",
341361// }),
342362// )
343- //
344363func IndexTypes (types map [string ]string ) * IndexAnnotation {
345364 return & IndexAnnotation {Types : types }
346365}
@@ -385,6 +404,9 @@ func (a IndexAnnotation) Merge(other schema.Annotation) schema.Annotation {
385404 a .DescColumns [column ] = desc
386405 }
387406 }
407+ if ant .IncludeColumns != nil {
408+ a .IncludeColumns = append (a .IncludeColumns , ant .IncludeColumns ... )
409+ }
388410 if ant .Type != "" {
389411 a .Type = ant .Type
390412 }
0 commit comments