@@ -22,6 +22,7 @@ type Entry struct {
22
22
Url string `gorm:"column:url"`
23
23
Password string `gorm:"column:password"`
24
24
Notes string `gorm:"column:notes"`
25
+ Tags string `gorm:"column:tags"`
25
26
Timestamp time.Time `gorm:"type:timestamp;default:(datetime('now','localtime'))"` // sqlite3
26
27
}
27
28
@@ -56,6 +57,16 @@ func (e1 *Entry) Copy(e2 *Entry) {
56
57
}
57
58
}
58
59
60
+ // Clone an entry
61
+ func (e1 * ExtendedEntry ) Copy (e2 * ExtendedEntry ) {
62
+
63
+ if e2 != nil {
64
+ e1 .FieldName = e2 .FieldName
65
+ e1 .FieldValue = e2 .FieldValue
66
+ e1 .EntryID = e2 .EntryID
67
+ }
68
+ }
69
+
59
70
// Create a new database
60
71
func openDatabase (filePath string ) (error , * gorm.DB ) {
61
72
@@ -219,13 +230,15 @@ func replaceCustomEntries(db *gorm.DB, entry *Entry, updatedEntries []CustomEntr
219
230
}
220
231
221
232
// Add a new entry to current database
222
- func addNewDatabaseEntry (title , userName , url , passwd , notes string , customEntries []CustomEntry ) error {
233
+ func addNewDatabaseEntry (title , userName , url , passwd , tags string ,
234
+ notes string , customEntries []CustomEntry ) error {
223
235
224
236
var entry Entry
225
237
var err error
226
238
var db * gorm.DB
227
239
228
- entry = Entry {Title : title , User : userName , Url : url , Password : passwd , Notes : notes }
240
+ entry = Entry {Title : title , User : userName , Url : url , Password : passwd , Tags : strings .TrimSpace (tags ),
241
+ Notes : notes }
229
242
230
243
err , db = openActiveDatabase ()
231
244
if err == nil && db != nil {
@@ -247,13 +260,20 @@ func addNewDatabaseEntry(title, userName, url, passwd, notes string, customEntri
247
260
}
248
261
249
262
// Update current database entry with new values
250
- func updateDatabaseEntry (entry * Entry , title , userName , url , passwd , notes string , customEntries []CustomEntry , flag bool ) error {
263
+ func updateDatabaseEntry (entry * Entry , title , userName , url , passwd , tags string ,
264
+ notes string , customEntries []CustomEntry , flag bool ) error {
251
265
252
266
var updateMap map [string ]interface {}
253
267
254
268
updateMap = make (map [string ]interface {})
255
269
256
- keyValMap := map [string ]string {"title" : title , "user" : userName , "url" : url , "password" : passwd , "notes" : notes }
270
+ keyValMap := map [string ]string {
271
+ "title" : title ,
272
+ "user" : userName ,
273
+ "url" : url ,
274
+ "password" : passwd ,
275
+ "notes" : notes ,
276
+ "tags" : tags }
257
277
258
278
for key , val := range keyValMap {
259
279
if len (val ) > 0 {
@@ -416,11 +436,22 @@ func removeDatabaseEntry(entry *Entry) error {
416
436
417
437
err , db = openActiveDatabase ()
418
438
if err == nil && db != nil {
439
+ var exEntries []ExtendedEntry
440
+
419
441
res := db .Delete (entry )
420
442
if res .Error != nil {
421
443
return res .Error
422
444
}
423
445
446
+ // Delete extended entries if any
447
+ exEntries = getExtendedEntries (entry )
448
+ if len (exEntries ) > 0 {
449
+ res = db .Delete (exEntries )
450
+ if res .Error != nil {
451
+ return res .Error
452
+ }
453
+ }
454
+
424
455
return nil
425
456
}
426
457
@@ -450,6 +481,31 @@ func cloneEntry(entry *Entry) (error, *Entry) {
450
481
return err , nil
451
482
}
452
483
484
+ // Clone extended entries for an entry and return error code
485
+ func cloneExtendedEntries (entry * Entry , exEntries []ExtendedEntry ) error {
486
+
487
+ var err error
488
+ var db * gorm.DB
489
+
490
+ err , db = openActiveDatabase ()
491
+ if err == nil && db != nil {
492
+ for _ , exEntry := range exEntries {
493
+ var exEntryNew ExtendedEntry
494
+
495
+ exEntryNew .Copy (& exEntry )
496
+ // Update the ID!
497
+ exEntryNew .EntryID = entry .ID
498
+
499
+ result := db .Create (& exEntryNew )
500
+ if result .Error != nil {
501
+ return result .Error
502
+ }
503
+ }
504
+ }
505
+
506
+ return err
507
+ }
508
+
453
509
// Return an iterator over all entries using the given order query keys
454
510
func iterateEntries (orderKey string , order string ) (error , []Entry ) {
455
511
0 commit comments