0

I need to initialize from ~/myConfig.json, which looks like:

{
  "databaseActive": "production",
  "databases": [
    {
      "name": "localhost",
      "PGDB": "asdf",
      "PGHOST": "localhost",
      "PGPASSWORD": "asdf",
      "PGPORT": "5432",
      "PGUSER": "asdf"
    },
    {
      "name": "production",
      "PGDB": "asdf",
      "PGHOST": "asdf.rds.amazonaws.com",
      "PGPASSWORD": "asdf",
      "PGPORT": "5432",
      "PGUSER": "asdf"
    }
  ]
}

This means I cannot call scalikejdbc.config.DBs.setupAll(). How might I use this JSON file to initialize scalikeJDBC from the appropriate database settings, according to the value of databaseActive?

Brhaka
  • 1,622
  • 3
  • 11
  • 31
Mike Slinn
  • 7,705
  • 5
  • 51
  • 85

1 Answers1

0

ScalikeJDBC offers only the HOCON reader. If you go with your own JSON config files, you need to write your own JSON parser which checks the databaseActive.

Parsing your config and binding it to ScalikeJDBC's config classess would be simple:

Kazuhiro Sera
  • 1,822
  • 12
  • 15
  • thank you for your quick response. I believe HOCON is advertised as "enhanced JSON". Can a HOCON file in the user home directory be parsed with the existing code? – Mike Slinn Jul 08 '19 at 02:55
  • I've never tried yet but it should be possible by calling ConfigFactory.parseFile instead of ConfigFactory.load – Kazuhiro Sera Jul 08 '19 at 06:19
  • https://github.com/scalikejdbc/scalikejdbc/blob/3.3.5/scalikejdbc-config/src/main/scala/scalikejdbc/config/TypesafeConfigReaderWithEnv.scala#L16 – Kazuhiro Sera Jul 08 '19 at 06:19
  • https://lightbend.github.io/config/latest/api/com/typesafe/config/ConfigFactory.html#parseFile-java.io.File- – Kazuhiro Sera Jul 08 '19 at 06:19