From dabc8824066d5c311a57932d03dc7b17decd9a2b Mon Sep 17 00:00:00 2001 From: Kazuhiro Oinuma Date: Mon, 3 Nov 2014 22:02:45 +0900 Subject: [PATCH 1/2] Add softdelete feature --- column.go | 2 ++ table.go | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/column.go b/column.go index 8656d4f6..ce0a7891 100644 --- a/column.go +++ b/column.go @@ -29,6 +29,7 @@ type Column struct { IsUpdated bool IsCascade bool IsVersion bool + IsSoftDelete bool fieldPath []string DefaultIsEmpty bool EnumOptions map[string]int @@ -52,6 +53,7 @@ func NewColumn(name, fieldName string, sqlType SQLType, len1, len2 int, nullable IsUpdated: false, IsCascade: false, IsVersion: false, + IsSoftDelete: false, fieldPath: nil, DefaultIsEmpty: false, EnumOptions: make(map[string]int), diff --git a/table.go b/table.go index 78eeacf9..ee15d113 100644 --- a/table.go +++ b/table.go @@ -18,6 +18,7 @@ type Table struct { Created map[string]bool Updated string Version string + SoftDelete string Cacher Cacher StoreEngine string Charset string @@ -83,6 +84,10 @@ func (table *Table) UpdatedColumn() *Column { return table.GetColumn(table.Updated) } +func (table *Table) SoftDeleteColumn() *Column { + return table.GetColumn(table.SoftDelete) +} + // add a column to table func (table *Table) AddColumn(col *Column) { table.columnsSeq = append(table.columnsSeq, col.Name) @@ -109,6 +114,9 @@ func (table *Table) AddColumn(col *Column) { if col.IsVersion { table.Version = col.Name } + if col.IsSoftDelete { + table.SoftDelete = col.Name + } } // add an index or an unique to table From 3e9907056787698c9419074d5a54b265a86d492f Mon Sep 17 00:00:00 2001 From: oinume Date: Wed, 5 Nov 2014 15:28:37 +0900 Subject: [PATCH 2/2] Tag name changed: softdelete -> deleted --- column.go | 4 ++-- table.go | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/column.go b/column.go index ce0a7891..34223de8 100644 --- a/column.go +++ b/column.go @@ -27,9 +27,9 @@ type Column struct { MapType int IsCreated bool IsUpdated bool + IsDeleted bool IsCascade bool IsVersion bool - IsSoftDelete bool fieldPath []string DefaultIsEmpty bool EnumOptions map[string]int @@ -51,9 +51,9 @@ func NewColumn(name, fieldName string, sqlType SQLType, len1, len2 int, nullable MapType: TWOSIDES, IsCreated: false, IsUpdated: false, + IsDeleted: false, IsCascade: false, IsVersion: false, - IsSoftDelete: false, fieldPath: nil, DefaultIsEmpty: false, EnumOptions: make(map[string]int), diff --git a/table.go b/table.go index ee15d113..f7c9d464 100644 --- a/table.go +++ b/table.go @@ -17,8 +17,8 @@ type Table struct { AutoIncrement string Created map[string]bool Updated string + Deleted string Version string - SoftDelete string Cacher Cacher StoreEngine string Charset string @@ -84,8 +84,8 @@ func (table *Table) UpdatedColumn() *Column { return table.GetColumn(table.Updated) } -func (table *Table) SoftDeleteColumn() *Column { - return table.GetColumn(table.SoftDelete) +func (table *Table) DeletedColumn() *Column { + return table.GetColumn(table.Deleted) } // add a column to table @@ -111,12 +111,12 @@ func (table *Table) AddColumn(col *Column) { if col.IsUpdated { table.Updated = col.Name } + if col.IsDeleted { + table.Deleted = col.Name + } if col.IsVersion { table.Version = col.Name } - if col.IsSoftDelete { - table.SoftDelete = col.Name - } } // add an index or an unique to table