setup.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2021-2023 EMQ Technologies Co., Ltd.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package store
  15. import (
  16. "github.com/lf-edge/ekuiper/internal/conf"
  17. "github.com/lf-edge/ekuiper/internal/pkg/store/definition"
  18. )
  19. func SetupDefault() error {
  20. dir, err := conf.GetDataLoc()
  21. if err != nil {
  22. return err
  23. }
  24. c := definition.Config{
  25. Type: "sqlite",
  26. ExtStateType: "sqlite",
  27. Redis: definition.RedisConfig{},
  28. Sqlite: definition.SqliteConfig{
  29. Path: dir,
  30. Name: "",
  31. },
  32. }
  33. return Setup(c)
  34. }
  35. func SetupWithKuiperConfig(kconf *conf.KuiperConf) error {
  36. dir, err := conf.GetDataLoc()
  37. if err != nil {
  38. return err
  39. }
  40. c := definition.Config{
  41. Type: kconf.Store.Type,
  42. ExtStateType: kconf.Store.ExtStateType,
  43. Redis: definition.RedisConfig{
  44. Host: kconf.Store.Redis.Host,
  45. Port: kconf.Store.Redis.Port,
  46. Password: kconf.Store.Redis.Password,
  47. Timeout: kconf.Store.Redis.Timeout,
  48. },
  49. Sqlite: definition.SqliteConfig{
  50. Path: dir,
  51. Name: kconf.Store.Sqlite.Name,
  52. },
  53. }
  54. return Setup(c)
  55. }
  56. func Setup(config definition.Config) error {
  57. s, err := newStores(config, "sqliteKV.db")
  58. if err != nil {
  59. return err
  60. }
  61. globalStores = s
  62. s, err = newStores(config, "cache.db")
  63. if err != nil {
  64. return err
  65. }
  66. cacheStores = s
  67. s, err = newExtStateStores(config, "extState.db")
  68. if err != nil {
  69. return err
  70. }
  71. extStateStores = s
  72. return nil
  73. }