Ivan FB fd6a71cdd7
chore: Bump dependencies for v0.31.0 (#2885)
* bump_dependencies.md: add nim-results dependency
* change imports stew/results to results
* switching to Nim 2.0.8
* waku.nimble: reflect the requirement nim 1.6.0 to 2.0.8
  Adding --mm:refc as nim 2.0 enables a new garbage collector that we're
  not yet ready to support
* adapt waku code to Nim 2.0
* gcsafe adaptations because Nim 2.0 is more strict
2024-07-09 13:14:28 +02:00

30 lines
888 B
Nim

import std/strutils, regex, results
proc validateDbUrl*(dbUrl: string): Result[string, string] =
## dbUrl mimics SQLAlchemy Database URL schema
## See: https://docs.sqlalchemy.org/en/14/core/engines.html#database-urls
let regex = re2"^\w+:\/\/.+:.+@[\w*-.]+:[0-9]+\/[\w*-.]+$"
let dbUrl = dbUrl.strip()
if "sqlite" in dbUrl or dbUrl == "" or dbUrl == "none" or dbUrl.match(regex):
return ok(dbUrl)
else:
return err("invalid 'db url' option format")
proc getDbEngine*(dbUrl: string): Result[string, string] =
let dbUrlParts = dbUrl.split("://", 1)
if dbUrlParts.len != 2:
return err("Incorrect dbUrl")
let engine = dbUrlParts[0]
return ok(engine)
proc getDbPath*(dbUrl: string): Result[string, string] =
let dbUrlParts = dbUrl.split("://", 1)
if dbUrlParts.len != 2:
return err("Incorrect dbUrl")
let path = dbUrlParts[1]
return ok(path)