ReasonML implementation of the pimp-my-sql wrapper.
This is a SQL wrapper that provides many convenience features and a "light" ORM interface that uses plain SQL as the underlying language. Currently it is only compatible with the [bs-mysql2] client.
Inside of a BuckleScript project:
yarn add bs-mysql2 bs-pimp-my-sqlThen add bs-mysql2 and bs-pimp-my-sql to your bs-dependencies
in bsconfig.json:
{
"bs-dependencies": [
"bs-mysql2",
"bs-pimp-my-sql"
]
}open Util.Operators;
let db =
Mysql.Connection.make(~host="127.0.0.1", ~port=3306, ~user="root", ());
let extractRows = response =>
switch response {
| PimpMySql.Promise.Mutation(_) => failwith("unexpected_mutation_result")
| PimpMySql.Promise.Select(s) => s.rows
};
let decoder_search = json => {
search: json |> Json.Decode.field("search", Json.Decode.string)
};
PimpMySql.raw(~db, ~sql="SELECT ? AS search", ~params=[|"%ssearch"|], ())
>>= extractRows
>>= Js.Array.map(decoder_search)
>>= Js.log
let decoder_result = json => {
result: json |> Json.Decode.field("result", Json.Decode.int)
};
PimpMySql.raw(~db, ~sql="SELECT 1 + ? + ? AS result", ~params=[|5, 6|], ())
>>= extractRows
>>= Js.Array.map(decoder_result)
>>= Js.logEverything not checked...
- Query Interface
- (raw) Raw SQL query
- (rawInsert) Raw SQL insert
- (rawUpdate) Raw SQL update
- INSERT
- (insert) basic wrapper
- UPDATE
- (update) Basic wrapper
- (updateWhereParams) with the
ObjectHashinterface - (increment) increment an integer column - must fit the
Counterinterface
- DELETE
- (delete) using a custom where clause
- (deleteById) - must fit the
PrimaryIdinterface
- Archive
- (deactivate) Deactivate a row - must fit the
Activatedinterface - (archive) Soft DELETE a row - must fit the
Archiveinterface - (archiveCompound) Soft Compound DELETE a row - must fit the
ArchiveCompoundinterface
- (deactivate) Deactivate a row - must fit the
- SELECT
- Transforms
- JSON column parse
- Nest dot notation transform
- Null out nested objects
- (get) using the Compositional SQL DSL
- getWhere) using a custom where clause
- (getOne) with custom where clause
- (getOneById) using the
idcolumn - must fitPrimaryIdinterface - (getWhereParams) using the
ObjectHashinterface
- Transforms
- Model
- Compositional SQL DSL
- Model Creation DSL
- Query interface
- INSERT
- (create)
- Pre-Create intercept
- Post-Create intercept
- UPDATE
- (update)
- Pre-Update intercept
- Post-Update intercept
- (increment) increment an integer column - must fit the
Counterinterface
- DELETE
- (delete) using a custom where clause
- (deleteById) - must fit the
PrimaryIdinterface
- Archive
- (deactivate) Deactivate a row - must fit the
Activatedinterface - (archive) Soft DELETE a row - must fit the
Archiveinterface - (archiveCompound) Soft Compound DELETE a row - must fit the
ArchiveCompoundinterface
- (deactivate) Deactivate a row - must fit the
- SELECT
- Transforms - (Dependent upon Query Interface implementation)
- (get) using the Compositional SQL DSL
- (getOne) with custom where clause
- (getOneById) using the
idcolumn - must fitPrimaryIdinterface - (getWhere) using a custom where clause
- (getWhereParams) using the
ObjectHashinterface
- INSERT
- Search - This needs some re-design to better fit ReasonML language semantics.
- Utilities
- TIMESTAMP conversion
-
ObjectHashinterface interpolation - Caching
