Skip to content

carmonw/bs-pimp-my-sql

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NPM Build Status Coverage Status

bs-pimp-my-sql

ReasonML implementation of the pimp-my-sql wrapper.

Why?

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.

How do I install it?

Inside of a BuckleScript project:

yarn add bs-mysql2 bs-pimp-my-sql

Then add bs-mysql2 and bs-pimp-my-sql to your bs-dependencies in bsconfig.json:

{
  "bs-dependencies": [
    "bs-mysql2",
    "bs-pimp-my-sql"
  ]
}

How do I use it?

Execute a raw SQL query.

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.log

What's missing?

Everything 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 ObjectHash interface
      • (increment) increment an integer column - must fit the Counter interface
    • DELETE
      • (delete) using a custom where clause
      • (deleteById) - must fit the PrimaryId interface
    • Archive
      • (deactivate) Deactivate a row - must fit the Activated interface
      • (archive) Soft DELETE a row - must fit the Archive interface
      • (archiveCompound) Soft Compound DELETE a row - must fit the ArchiveCompound interface
    • 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 id column - must fit PrimaryId interface
      • (getWhereParams) using the ObjectHash interface
  • 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 Counter interface
      • DELETE
        • (delete) using a custom where clause
        • (deleteById) - must fit the PrimaryId interface
      • Archive
        • (deactivate) Deactivate a row - must fit the Activated interface
        • (archive) Soft DELETE a row - must fit the Archive interface
        • (archiveCompound) Soft Compound DELETE a row - must fit the ArchiveCompound interface
      • SELECT
        • Transforms - (Dependent upon Query Interface implementation)
        • (get) using the Compositional SQL DSL
        • (getOne) with custom where clause
        • (getOneById) using the id column - must fit PrimaryId interface
        • (getWhere) using a custom where clause
        • (getWhereParams) using the ObjectHash interface
  • Search - This needs some re-design to better fit ReasonML language semantics.
  • Utilities
    • TIMESTAMP conversion
    • ObjectHash interface interpolation
    • Caching

About

ReasonML rewrite of the Pimp'd out SQL wrapper

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • OCaml 100.0%