setup.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2021-2022 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. Redis: definition.RedisConfig{},
  27. Sqlite: definition.SqliteConfig{
  28. Path: dir,
  29. Name: "",
  30. },
  31. }
  32. return Setup(c)
  33. }
  34. func SetupWithKuiperConfig(kconf *conf.KuiperConf) error {
  35. dir, err := conf.GetDataLoc()
  36. if err != nil {
  37. return err
  38. }
  39. c := definition.Config{
  40. Type: kconf.Store.Type,
  41. Redis: definition.RedisConfig{
  42. Host: kconf.Store.Redis.Host,
  43. Port: kconf.Store.Redis.Port,
  44. Password: kconf.Store.Redis.Password,
  45. Timeout: kconf.Store.Redis.Timeout,
  46. },
  47. Sqlite: definition.SqliteConfig{
  48. Path: dir,
  49. Name: kconf.Store.Sqlite.Name,
  50. },
  51. }
  52. return Setup(c)
  53. }
  54. func Setup(config definition.Config) error {
  55. s, err := newStores(config, "sqliteKV.db")
  56. if err != nil {
  57. return err
  58. }
  59. globalStores = s
  60. s, err = newStores(config, "cache.db")
  61. if err != nil {
  62. return err
  63. }
  64. cacheStores = s
  65. return nil
  66. }