{"id":17159158,"url":"https://github.com/scull7/bs-pimp-my-sql","last_synced_at":"2025-03-24T14:45:17.755Z","repository":{"id":122694720,"uuid":"119291790","full_name":"scull7/bs-pimp-my-sql","owner":"scull7","description":"ReasonML rewrite of the Pimp'd out SQL wrapper","archived":false,"fork":false,"pushed_at":"2018-08-17T04:01:52.000Z","size":286,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-28T02:03:25.253Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scull7.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-28T19:46:35.000Z","updated_at":"2018-08-25T15:53:45.000Z","dependencies_parsed_at":"2023-03-10T07:45:27.474Z","dependency_job_id":null,"html_url":"https://github.com/scull7/bs-pimp-my-sql","commit_stats":{"total_commits":306,"total_committers":3,"mean_commits":102.0,"dds":"0.20261437908496727","last_synced_commit":"c5c8caee2863f1d3e674f5d0acd32d5a9b23c6c9"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scull7%2Fbs-pimp-my-sql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scull7%2Fbs-pimp-my-sql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scull7%2Fbs-pimp-my-sql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scull7%2Fbs-pimp-my-sql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scull7","download_url":"https://codeload.github.com/scull7/bs-pimp-my-sql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245294711,"owners_count":20591898,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T22:13:29.960Z","updated_at":"2025-03-24T14:45:17.729Z","avatar_url":"https://github.com/scull7.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM](https://nodei.co/npm/bs-pimp-my-sql.png)](https://nodei.co/npm/bs-pimp-my-sql/)\n[![Build Status](https://www.travis-ci.org/scull7/bs-pimp-my-sql.svg?branch=master)](https://www.travis-ci.org/scull7/bs-pimp-my-sql)\n[![Coverage Status](https://coveralls.io/repos/github/scull7/bs-pimp-my-sql/badge.svg?branch=master)](https://coveralls.io/github/scull7/bs-pimp-my-sql?branch=master)\n\n# bs-pimp-my-sql\nReasonML implementation of the [pimp-my-sql] wrapper.\n\n## Why?\n\nThis is a SQL wrapper that provides many convenience features and a \"light\" ORM interface that\nuses plain SQL as the underlying language.  Currently it is only compatible with the [bs-mysql2]\nclient.\n\n## How do I install it?\n\nInside of a BuckleScript project:\n```shell\nyarn add @glennsl/bs-json bs-mysql2 bs-pimp-my-sql bs-result bs-sql-common bs-sql-composer\n```\n\nThen add `@glennsl/bs-json`, `bs-mysql2`, `bs-pimp-my-sql`, `bs-result`, `bs-sql-common`,\nand `bs-sql-composer` to your `bs-dependencies` in `bsconfig.json`:\n\n```json\n{\n  \"bs-dependencies\": [\n    \"@glennsl/bs-json\",\n    \"bs-mysql2\",\n    \"bs-pimp-my-sql\",\n    \"bs-result\",\n    \"bs-sql-common\",\n    \"bs-sql-composer\"\n  ]\n}\n```\n\n## How do I use it?\n\n### General Usage\n\nThe way you should access modules in `PimpMySql` is as follows:\n\n```reason\nPimpMySql.\u003cModule\u003e\n```\n\nOf course you can always directly call the internal files, namespaced with `PimpMySql_`, but\nthat is not recommended since these files are implementation details.\n\n### Using the Factory Model.\n\nBelow are the requirements necessary to use the FactoryModel. Each requirement is documented\nwith examples below.  The requirements include: creating the connection, creating the config,\nand creating the model.\n\n#### Creating the Connection\n\n```reason\nmodule Sql = SqlCommon.Make_sql(MySql2);\n\nlet conn = Sql.connect(~host=\"127.0.0.1\", ~port=3306, ~user=\"root\", ~database=\"example\", ());\n```\n\n\n#### Creating the Config\n\nCreating the Config is quite simple, below is a brief explanation\nfor each field in the Config:\n\n- t: the record type that will be mapped to\n- table: the name of the database table\n- decoder: a function to map the query response to t\n- base: the base query for the model, try to keep this as thin as possible\n  (i.e. minimal where clauses, etc.)\n\n```reason\nlet table = \"animal\";\n\ntype animal = {\n  id: int,\n  type_: string,\n  deleted: int,\n};\n\nmodule Config = {\n  type t = animal;\n  let table = table;\n  let decoder = json =\u003e\n    Json.Decode.{\n      id: field(\"id\", int, json),\n      type_: field(\"type_\", string, json),\n      deleted: field(\"deleted\", int, json),\n    };\n  let base =\n    SqlComposer.Select.(\n      select\n      |\u003e field({j|$table.`id`|j})\n      |\u003e field({j|$table.`type_`|j})\n      |\u003e field({j|$table.`deleted`|j})\n      |\u003e order_by(`Desc({j|$table.`id`|j}))\n    );\n};\n```\n\n#### Creating the Model\n\nCreating the model is quite simple once the Config is setup:\n\n```reason\nmodule Model = PimpMySql.FactoryModel.Generator(Config);\n```\n\n#### Usage Examples\n\nBelow are a few examples on how to use the model, refer to the documentation\nbelow for the full list of functions/methods:\n\n```reason\nModel.getOneById(1, conn)\n|\u003e Js.Promise.then_(res =\u003e\n     (\n       switch (res) {\n       | Some(x) =\u003e \u003chandle case for successfully fetching a row\u003e\n       | None =\u003e \u003chandle case for failing to fetch a row\u003e\n       }\n     )\n     |\u003e Js.Promise.resolve\n   );\n\nModel.archiveOneById(1, conn)\n|\u003e Js.Promise.then_(res =\u003e\n     (\n       switch (res) {\n       | Result.Ok(Some(x)) =\u003e \u003chandle case for successfully archiving a row and returning the result\u003e\n       | Result.Ok(None) =\u003e \u003chandle case for successfully archiving a row and returning no result\u003e\n       | None =\u003e \u003chandle case for failing to archive a row\u003e\n       }\n     )\n     |\u003e Js.Promise.resolve\n   );\n```\n\n*Note: you will notice that some methods will return `Result.Ok(None)`, this means that the row(s)\nwere altered successfully but when an attempt to fetch the same row(s) was made the operation failed;\nthis is because the Model's base query filters out the row(s) after update.*\n\n## What's missing?\n\nEverything not checked...\n\n- [ ] Query Interface\n  - [x] _(raw)_ Raw SQL query\n  - [ ] _(rawInsert)_ Raw SQL insert\n  - [ ] _(rawUpdate)_ Raw SQL update\n  - [x] INSERT\n    - [x] _(insertOne)_ basic wrapper\n    - [x] _(insertBatch)_ basic wrapper\n  - [ ] UPDATE\n    - [x] _(updateOneById)_ Basic wrapper using the `id` column - must fit `PrimaryId` interface\n    - [ ] _(updateWhereParams)_ with the `ObjectHash` interface\n    - [x] _(incrementOneById)_ increment an integer column using the `id` column - must fit the `Counter`\n          and `PrimaryId` interfaces\n  - [x] DELETE\n    - [x] _(deleteBy)_ using a custom where clause\n    - [x] _(deleteOneById)_ - must fit the `PrimaryId` interface\n  - [x] Archive\n    - [x] _(deactivateOneById)_ Deactivate a row using the `id` column - must fit the `Activated` and\n          `PrimaryId` interfaces\n    - [x] _(archiveOneById)_ Soft DELETE a row using the `id` column - must fit the `Archive` interface\n    - [x] _(archiveCompoundBy)_ Soft Compound DELETE using a custom where clause - must fit the\n          `ArchiveCompound` interface\n    - [x] _(archiveCompoundOneById)_ Soft Compound DELETE a row using the `id` column - must fit the\n          `ArchiveCompound` and `PrimaryId` interfaces\n  - [ ] SELECT\n    - [ ] Transforms\n      - [ ] JSON column parse\n      - [ ] Nest dot notation transform\n      - [ ] Null out nested objects\n    - [x] _(get)_ using the Compositional SQL DSL\n    - [x] _(getByIdList)_ using the `id` column - must fit `PrimaryId` interface\n    - [x] _(getOneBy)_ with custom where clause\n    - [x] _(getOneById)_ using the `id` column - must fit `PrimaryId` interface\n    - [x] _(getWhere)_ using a custom where clause\n    - [ ] _(getWhereParams)_ using the `ObjectHash` interface\n- [ ] Model\n  - [x] Compositional SQL DSL\n  - [x] Model Creation DSL\n  - [x] Query interface\n    - [ ] INSERT\n      - [x] _(insertOne)_\n      - [x] _(insertBatch)_\n      - [ ] Pre-Create intercept\n      - [ ] Post-Create intercept\n    - [ ] UPDATE\n      - [x] _(updateOneById)_ using the `id` column - must fit `PrimaryId` interface\n      - [x] _(incrementOneById)_ increment an integer column using the `id` column - must fit the `Counter`\n            and `PrimaryId` interfaces\n      - [ ] Pre-Update intercept\n      - [ ] Post-Update intercept\n    - [x] DELETE\n      - [x] _(deleteBy)_ using a custom where clause\n      - [x] _(deleteOneById)_ - must fit the `PrimaryId` interface\n    - [x] Archive\n      - [x] _(deactivateOneById)_ Deactivate a row using the `id` column - must fit the `Activated` and\n            `PrimaryId` interfaces\n      - [x] _(archiveOneById)_ Soft DELETE a row using the `id` column - must fit the `Archive` interface\n      - [x] _(archiveCompoundBy)_ Soft Compound DELETE using a custom where clause - must fit the\n            `ArchiveCompound` interface\n      - [x] _(archiveCompoundOneById)_ Soft Compound DELETE a row using the `id` column - must fit the\n            `ArchiveCompound` and `PrimaryId` interfaces\n    - [ ] SELECT\n      - [ ] Transforms - _(Dependent upon Query Interface implementation)_\n      - [x] _(get)_ using the Compositional SQL DSL\n      - [x] _(getByIdList)_ using the `id` column - must fit `PrimaryId` interface\n      - [x] _(getOneBy)_ with custom where clause\n      - [x] _(getOneById)_ using the `id` column - must fit `PrimaryId` interface\n      - [x] _(getWhere)_ using a custom where clause\n      - [ ] _(getWhereParams)_ using the `ObjectHash` interface\n- [ ] Search - _This needs some re-design to better fit ReasonML language semantics._\n- [ ] Utilities\n  - [ ] TIMESTAMP conversion\n  - [ ] `ObjectHash` interface interpolation\n  - [ ] Caching\n\n[pimp-my-sql]: https://github.com/influentialpublishers/pimp-my-sql\n[bs-mysql]: https://github.com/davidgomes/bs-mysql\n[mysql2]: https://www.npmjs.com/package/mysql2\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscull7%2Fbs-pimp-my-sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscull7%2Fbs-pimp-my-sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscull7%2Fbs-pimp-my-sql/lists"}