graninas / Hydra

Hydra is a full-fledged framework for building web services, multithreaded and concurrent applications with SQL and KV DB support.
BSD 3-Clause "New" or "Revised" License
184 stars 13 forks source link

Add MySQL backend #18

Open graninas opened 4 years ago

graninas commented 4 years ago

Add MySQL backend (beam-mysql library).

yaitskov commented 4 years ago

@graninas,

I located all places specific to Sqlite and have problem with handling connection parameters. Sqlite use connect and accepts a path to db file. Mysql also has connect function, but it accepts structure. I spot mysqlUriSyntax in beam-mysql, which contains parser for ConnectInfo but it is hidden inside the function, mean while mysqlUriSyntax has complex type signature and and doing extra - creates a connection. BeamURIOpeners is not used in Hydra.

So there is a dilemma: I can copy past parsing code or modify beam-mysql and extract pure function

Uri -> ConnectInfo

Imho such function should reside just in mysql.

The alternative is to figure out how to call mysqlUriSyntax in Hydra. It contradicts the way how Sqlite connection is established.

graninas commented 4 years ago

Hi @yaitskov , let me share some context with you regarding this.

There is a proprietary framework we built in Juspay, and it's a very close analogue to Hydra (because I used the ideas and design of Hydra for that framework). There, we have an SQL subsystem implemented similarly with Hydra, and we have 3 different sql backends there: SQLite, MySQL, Postgres. It's very important to follow the same design because it's tested and well-understood. Also, Hydra can be used as an open source documentation to that framework.

Unfortunately, I can't share the code of the private framework, but at least I can show you the connection types and interfaces. Still it may be insufficient to implement this task.

Here what we have in the private framework (a small citation):

data DBConfig beM
  = MockConfig ConnTag
  | PostgresPoolConf ConnTag PostgresConfig PoolConfig
  -- ^ config for 'Pool' with Postgres connections
  | MySQLPoolConf ConnTag MySQLConfig PoolConfig
  -- ^ config for 'Pool' with MySQL connections
  | SQLitePoolConf ConnTag SQliteDBname PoolConfig
  -- ^ config for 'Pool' with SQlite connections
  deriving (Show, Eq, Ord, Generic, ToJSON, FromJSON)
data SqlConn beM
  = MockedPool ConnTag
  | PostgresPool ConnTag (DP.Pool BP.Connection)
  -- ^ 'Pool' with Postgres connections
  | MySQLPool ConnTag (DP.Pool MySQL.Connection)
  -- ^ 'Pool' with MySQL connections
  | SQLitePool ConnTag (DP.Pool SQLite.Connection)
  -- ^ 'Pool' with SQLite connections
  deriving (Generic)

So I'm not really sure if it makes sense for you to implement this task. Maybe it's better to leave it to me.