No Description

PhotoLocalStorage.swift 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // PhotoLocalStorage.swift
  3. // PaiAi
  4. //
  5. // Created by LISA on 2017/4/19.
  6. // Copyright © 2017年 yb. All rights reserved.
  7. //
  8. import UIKit
  9. //import ObjectMapper
  10. //import SQLite
  11. //
  12. //public struct PhotoLocalStorage {
  13. //
  14. // let photoId = Expression<String>("photoId")
  15. // let photoInfo = Expression<Data>("photoInfo")
  16. // let creatAt = Expression<TimeInterval>("creatAt")
  17. //
  18. // static let instance = PhotoLocalStorage()
  19. // var db: Connection?
  20. //
  21. // init() {
  22. // db = try? Connection(path)
  23. // }
  24. //
  25. // private let path: String = {
  26. // let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first ?? ""
  27. // let finalPath = path.appending("/group_photo.db")
  28. //// printLog(finalPath)
  29. // return finalPath
  30. // }()
  31. //
  32. // func query(group_id: String) -> [PhotoItem]? {
  33. //// let table = Table(group_id.digestString(algorithm: .md5))
  34. //// do {
  35. //// guard let photos = try db?.prepare(table) else {
  36. //// return nil
  37. //// }
  38. //// return photos.compactMap({ (photo) -> PhotoItem? in
  39. //// let data = photo[photoInfo]
  40. //// guard let dict = NSKeyedUnarchiver.unarchiveObject(with: data) as? [String: AnyObject] else {
  41. //// return nil
  42. //// }
  43. //// return PhotoItem(data: dict)
  44. //// })
  45. //// } catch {
  46. //// return nil
  47. //// }
  48. // return nil
  49. // }
  50. //
  51. // func saveDataToLocal(models: [PhotoItem], group_id: String) {
  52. //// let table = Table(group_id.digestString(algorithm: .md5))
  53. //// do {
  54. //// try db?.transaction {
  55. //// try db?.run(table.create(ifNotExists: true, block: { (table) in
  56. //// table.column(photoId, unique: true)
  57. //// table.column(photoInfo)
  58. //// table.column(creatAt)
  59. //// }))
  60. ////
  61. //// for model in models {
  62. //// let data = NSKeyedArchiver.archivedData(withRootObject: model.toJSON())
  63. //// let insert = table.insert(or: .replace,
  64. //// photoInfo <- data,
  65. //// creatAt <- (model.create_at.timeIntervalSince1970) ,
  66. //// photoId <- model.photo_id)
  67. //// _ = try db?.run(insert)
  68. //// }
  69. ////
  70. //// }
  71. //// } catch {
  72. //// }
  73. // }
  74. //
  75. // func updateLocalData(PhotoItem: PhotoItem) {
  76. //// let table = Table(PhotoItem.group_id.digestString(algorithm: .md5)).filter(photoId == PhotoItem.photo_id)
  77. //// let photoData = NSKeyedArchiver.archivedData(withRootObject: PhotoItem.toJSON())
  78. //// do {
  79. //// try db?.run(table.update(photoInfo <- photoData))
  80. //// } catch {
  81. ////
  82. //// }
  83. // }
  84. //
  85. // func removeLocalData(group_id: String) {
  86. //// removeGroupInfoRecent(groupId: group_id)
  87. //// let table = Table(group_id.digestString(algorithm: .md5))
  88. //// _ = table.drop(ifExists: true)
  89. // }
  90. //}