localstorage.lua 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. -- localstorage.lua
  2. local localstorage = {}
  3. localstorage.__index = localstorage
  4. --[[
  5. 创建一个新的 fw_localstorage 对象
  6. @return 返回一个新的 fw_localstorage 对象
  7. ]]
  8. function localstorage.new(db)
  9. local instance = setmetatable({}, localstorage)
  10. if db == nil then
  11. instance.module = fw_localstorage.new()
  12. else
  13. instance.module = db
  14. end
  15. return instance
  16. end
  17. --[[
  18. 打开本地存储
  19. @param dirpath 目录路径
  20. @return 是否成功打开
  21. ]]
  22. function localstorage:open(dirpath)
  23. return self.module:open(dirpath)
  24. end
  25. --[[
  26. 关闭本地存储
  27. ]]
  28. function localstorage:close()
  29. self.module:close()
  30. end
  31. --[[
  32. 清空数据库
  33. ]]
  34. function localstorage:clear()
  35. self.module:clear()
  36. end
  37. --[[
  38. 写入数据
  39. @param name 名称
  40. @param value 值
  41. @return 是否成功写入
  42. ]]
  43. function localstorage:write(name, value)
  44. return self.module:write(name, value)
  45. end
  46. --[[
  47. 读取数据
  48. @param name 名称
  49. ]]
  50. function localstorage:read(name)
  51. return self.module:read(name)
  52. end
  53. --[[
  54. 删除数据
  55. @param name 名称
  56. @return 是否成功删除
  57. ]]
  58. function localstorage:del(name)
  59. return self.module:del(name)
  60. end
  61. --[[
  62. 检查数据是否存在
  63. @param name 名称
  64. @return 是否存在
  65. ]]
  66. function localstorage:exist(name)
  67. return self.module:exist(name)
  68. end
  69. function localstorage:self()
  70. return self.module:self()
  71. end
  72. function localstorage:last_error()
  73. return self.module:last_error()
  74. end
  75. return localstorage