{"id":30522868,"url":"https://github.com/adhyapranata/crane","last_synced_at":"2025-08-26T19:29:22.133Z","repository":{"id":44077378,"uuid":"205398359","full_name":"adhyapranata/crane","owner":"adhyapranata","description":"React Native SQLite query builder. Supports expo-sqlite and react-native-sqlite-storage.","archived":false,"fork":false,"pushed_at":"2023-01-04T08:35:16.000Z","size":3248,"stargazers_count":28,"open_issues_count":18,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-09T03:51:38.082Z","etag":null,"topics":["hacktoberfest","offline-app","offline-first","query-builder","react-native","react-native-sqlite","sqlite","sqlite3"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/adhyapranata.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-30T14:28:08.000Z","updated_at":"2025-03-18T15:43:43.000Z","dependencies_parsed_at":"2023-02-02T05:32:02.328Z","dependency_job_id":null,"html_url":"https://github.com/adhyapranata/crane","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/adhyapranata/crane","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adhyapranata%2Fcrane","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adhyapranata%2Fcrane/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adhyapranata%2Fcrane/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adhyapranata%2Fcrane/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adhyapranata","download_url":"https://codeload.github.com/adhyapranata/crane/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adhyapranata%2Fcrane/sbom","scorecard":{"id":166384,"data":{"date":"2025-08-11","repo":{"name":"github.com/adhyapranata/crane","commit":"7dcceb45e52f3705f19292449b482aeeee26b7d4"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.7,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 1/18 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 14 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"45 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3","Warn: Project is vulnerable to: MAL-2023-462","Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6","Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44","Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988","Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj","Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9","Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw","Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc","Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh","Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36","Warn: Project is vulnerable to: GHSA-52f5-9888-hmc6","Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q","Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh","Warn: Project is vulnerable to: GHSA-6chw-6frg-f759"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-16T15:00:09.606Z","repository_id":44077378,"created_at":"2025-08-16T15:00:09.606Z","updated_at":"2025-08-16T15:00:09.606Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272216454,"owners_count":24893706,"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","status":"online","status_checked_at":"2025-08-26T02:00:07.904Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["hacktoberfest","offline-app","offline-first","query-builder","react-native","react-native-sqlite","sqlite","sqlite3"],"created_at":"2025-08-26T19:29:19.635Z","updated_at":"2025-08-26T19:29:22.127Z","avatar_url":"https://github.com/adhyapranata.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Crane: React Native SQLite Query Builder\n\n[![Crane](./banner.png)](https://github.com/adhyapranata/crane)\n\n[![Code Climate](https://img.shields.io/codeclimate/maintainability/adhyapranata/crane.svg)](https://codeclimate.com/github/adhyapranata/crane)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\nCrane is a query builder for React Native extracted from Laravel's [illuminate/database](https://github.com/illuminate/database).\nThis library supports both [react-native-sqlite-storage](https://github.com/andpor/react-native-sqlite-storage) and [expo sqlite](https://docs.expo.io/versions/latest/sdk/sqlite/).  \n\n## Table of Contents\n\n- [Demo](#demo)\n- [Installation](#installation)\n- [Getting Started](#getting-started)\n- [Documentation](#documentation)\n- [Contributing](#contributing)\n- [Support + Feedback](#support--feedback)\n- [Thank You](#thank-you)\n- [License](#license)\n\n## Demo\nFor a demo, [click here](https://github.com/adhyapranata/crane-expo-demo).\n\n## Installation \n\nCrane *requires* SQLite driver in order to work.\n\nIf you are using expo, install the `expo-sqlite`\n```bash\nexpo install expo-sqlite\n```\n\nIf you are using bare React Native, install the `react-native-sqlite-storage`. For detail instruction, please refer to the package [documentation](https://github.com/andpor/react-native-sqlite-storage)\n```bash\nyarn add react-native-sqlite-storage\n```\n\nFinally, install `crane`\n\n```bash\nyarn add crane-query-builder\n```\n\n## Getting Started\n\n### For Expo\n```javascript\nimport React, { useEffect } from 'react';\nimport { StyleSheet, Text, View } from 'react-native';\nimport { Asset } from 'expo-asset';\nimport * as SQLite from 'expo-sqlite';\nimport * as FileSystem from 'expo-file-system';\nimport Builder, { DB } from 'crane'; // Import the library\n\n\nexport default function App() {\n  useEffect(() =\u003e {\n    testDB();\n  }, []);\n\n  return (\n    \u003cView style={styles.container}\u003e\n      \u003cText\u003eOpen up App.js to start working on your app!\u003c/Text\u003e\n    \u003c/View\u003e\n  );\n}\n\nexport async function testDB() {\n  await initDB();\n  await getAlbums();\n}\n\nexport async function initDB() {\n  await testDriver();\n  await loadDB();\n}\n\nexport async function testDriver() {\n  const dummy = SQLite.openDatabase('dummy.db');\n\n  try {\n    await dummy.transaction(tx =\u003e tx.executeSql(''));\n  } catch (e) {\n    if (this.state.debugEnabled)\n      console.log('error while executing SQL in dummy DB');\n  }\n}\n\nexport async function loadDB() {\n  let dbFile = await FileSystem.getInfoAsync(`${FileSystem.documentDirectory}SQLite/db.db`);\n\n  if (!dbFile.exists)\n    makeDir();\n\n  // Add connection using DB.addConnection\n  DB.addConnection({\n    type: 'expo',\n    driver: SQLite,\n    name: 'db.db',\n  });\n}\n\nexport async function makeDir() {\n  await FileSystem.downloadAsync(\n    Asset.fromModule(require('./assets/db/db.db')).uri,\n    `${FileSystem.documentDirectory}SQLite/db.db`\n  );\n}\n\n\nexport async function getAlbums() {\n  // Build your query\n  let albums = await Builder()\n    .table('albums')\n    .where('ArtistId', '\u003e', 200)\n    .get();\n\n  console.log(albums);\n}\n\nconst styles = StyleSheet.create({\n  container: {\n    flex: 1,\n    backgroundColor: '#fff',\n    alignItems: 'center',\n    justifyContent: 'center',\n  },\n});\n```\n\n### For Bare React Native\n```javascript\n// doc coming soon...\n```\n\n## Documentation\n\n- [Retrieving Results](#retrieving-results)\n- [Selects](#selects)\n- [Raw Expressions](#raw-expressions)\n- [Joins](#joins)\n- [Unions](#unions)\n- [Where Clauses](#where-clauses)\n- [Ordering, Grouping, Limit \u0026 Offset](#ordering-grouping-limit--offset)\n- [Inserts](#inserts)\n- [Updates](#updates)\n- [Deletes](#deletes)\n\n### Retrieving Results\n**Retrieving All Rows From A Table**\n\nYou may use the `table` method begin a query. The table method returns a fluent query builder instance for the given table, allowing you to chain more constraints onto the query and then finally get the results using the `get` method:\n```javascript\nlet albums = await Builder()\n    .table('albums')\n    .get()\n```\n\n**Retrieving A Single Row / Column From A Table**\n\nIf you just need to retrieve a single row from the database table, you may use the `first` method.\n```javascript\nlet albums = await Builder()\n    .table('albums')\n    .where('ArtistId', '\u003e', 200)\n    .first()\n```\n\nIf you don't even need an entire row, you may extract a single value from a record using the value method. This method will return the value of the column directly:\n```javascript\nlet employees = await Builder()\n    .table('employees')\n    .where('Title', 'Sales Support Agent')\n    .value('FirstName')\n```\n\nTo retrieve a single row by its `id` column value, use the `find` method:\n```javascript\nlet users = await Builder()\n    .table('users')\n    .find(4)\n```\n\n**Retrieving A List Of Column Values**\n\nIf you would like to retrieve a Collection containing the values of a single column, you may use the `pluck` method. In this example, we'll retrieve a Collection of role titles:\n```javascript\nlet employees = await Builder()\n    .table('employees')\n    .where('Title', 'Sales Support Agent')\n    .pluck('FirstName', 'LastName')\n```\n\n#### Aggregates\nThe query builder also provides a variety of aggregate methods such as count, `max`, `min`, `avg`, and `sum`. You may call any of these methods after constructing your query:\n```javascript\nlet customers = await Builder()\n    .table('customers')\n    .count()\n\nlet invoices = await Builder()\n    .table('invoices')\n    .max('total')\n```\n\nYou may combine these methods with other clauses:\n```javascript\nlet invoices = await Builder()\n    .table('invoices')\n    .where('BillingState', 'CA')\n    .avg('total')\n```\n\n**Determining If Records Exist**\n\nInstead of using the `count` method to determine if any records exist that match your query's constraints, you may use the `exists` and `doesntExist` methods:\n```javascript\nlet customersA = await Builder()\n    .table('customers')\n    .where('PostalCode', '14700')\n    .exists()\n\nlet customersB = await Builder()\n    .table('customers')\n    .where('PostalCode', '14700')\n    .doesntExist()\n```\n\n### Selects\n**Specifying A Select Clause**\n\nYou may not always want to select all columns from a database table. Using the `select` method, you can specify a custom `select` clause for the query:\n```javascript\nlet customers = await Builder()\n  .table('customers')\n  .select('FirstName', 'Phone as CustomerPhone')\n  .get()\n```\n\nThe `distinct` method allows you to force the query to return distinct results:\n```javascript\nlet customers = await Builder()\n  .table('customers')\n  .distinct()\n  .get()\n```\n\nIf you already have a query builder instance and you wish to add a column to its existing select clause, you may use the `addSelect` method:\n```javascript\nlet query = Builder()\n  .table('customers')\n  .select('FirstName')\n\nlet customers = await query\n  .addSelect('LastName')\n  .get()\n```\n\n### Raw Expressions\nSometimes you may need to use a raw expression in a query. To create a raw expression, you may use the `raw` method:\n```javascript\nlet users = await Builder().table('users')\n  .select(Builder().raw('count(*) as user_count, status'))\n  .where('status', '\u003c\u003e', 1)\n  .groupBy('status')\n  .get()\n```\n\n\u003e Raw statements will be injected into the query as strings, so you should be extremely careful to not create SQL injection vulnerabilities.\n\n##### Raw Methods\nInstead of using `raw`, you may also use the following methods to insert a raw expression into various parts of your query.\n\n`selectRaw`\n\nThe selectRaw method can be used in place of `addSelect(Builder().raw(...))`. This method accepts an optional array of bindings as its second argument:\n```javascript\nlet orders = await Builder()\n  .table('orders')\n  .selectRaw('price * ? as price_with_tax', [1.0825])\n  .get()\n````\n\n`whereRaw / orWhereRaw`\n\nThe `whereRaw` and `orWhereRaw` methods can be used to inject a raw where clause into your query. These methods accept an optional array of bindings as their second argument:\n```javascript\nlet orders = await Builder()\n  .table('orders')\n  .whereRaw('price \u003e IF(state = \"TX\", ?, 100)', [200])\n  .get()\n````\n\n`havingRaw / orHavingRaw`\n\nThe `havingRaw` and `orHavingRaw` methods may be used to set a raw string as the value of the `having` clause. These methods accept an optional array of bindings as their second argument:\n```javascript\nlet orders = await Builder()\n  .table('orders')\n  .select('department', Builder().raw('SUM(price) as total_sales'))\n  .groupBy('department')\n  .havingRaw('SUM(price) \u003e ?', [2500])\n  .get()\n````\n\n`orderByRaw`\n\nThe `orderByRaw` method may be used to set a raw string as the value of the `order by` clause:\n```javascript\nlet orders = await Builder()\n  .table('orders')\n  .orderByRaw('updated_at - created_at DESC')\n  .get()\n````\n\n### Joins\n**Inner Join Clause**\n\nThe query builder may also be used to write join statements. To perform a basic \"inner join\", you may use the `join` method on a query builder instance. The first argument passed to the `join` method is the name of the table you need to join to, while the remaining arguments specify the column constraints for the join. You can even join to multiple tables in a single query:\n```javascript\nlet users = await Builder()\n  .table('users')\n  .join('contacts', 'users.id', '=', 'contacts.user_id')\n  .join('orders', 'users.id', '=', 'orders.user_id')\n  .select('users.*', 'contacts.phone', 'orders.price')\n  .get()\n```\n\n**Left Join / Right Join Clause**\n\nIf you would like to perform a \"left join\" or \"right join\" instead of an \"inner join\", use the `leftJoin` or `rightJoin` methods. These methods have the same signature as the `join` method:\n```javascript\nlet usersA = await Builder()\n  .table('users')\n  .leftJoin('posts', 'users.id', '=', 'posts.user_id')\n  .get()\n\nlet usersB = await Builder()\n  .table('users')\n  .rightJoin('posts', 'users.id', '=', 'posts.user_id')\n  .get()\n```\n\n**Cross Join Clause**\n\nTo perform a \"cross join\" use the `crossJoin` method with the name of the table you wish to cross join to. Cross joins generate a cartesian product between the first table and the joined table:\n```javascript\nlet users = await Builder()\n  .table('sizes')\n  .crossJoin('colours')\n  .get()\n```\n\n**Advanced Join Clauses**\n\nYou may also specify more advanced join clauses. To get started, pass a `Closure` as the second argument into the `join` method. The `Closure` will receive a `JoinClause` object which allows you to specify constraints on the `join` clause:\n```javascript\nawait Builder()\n  .table('users')\n  .join('contacts', join =\u003e {\n    join\n      .on('users.id', '=', 'contacts.user_id')\n      .orOn(...)\n  })\n  .get()\n```\nIf you would like to use a \"where\" style clause on your joins, you may use the `where` and `orWhere` methods on a join. Instead of comparing two columns, these methods will compare the column against a value:\n```javascript\nawait Builder()\n  .table('users')\n  .join('contacts', join =\u003e {\n      join\n        .on('users.id', '=', 'contacts.user_id')\n        .where('contacts.user_id', '\u003e', 5)\n  })\n  .get()\n```\n\n**Subquery Joins**\n\nYou may use the `joinSub`, `leftJoinSub`, and `rightJoinSub` methods to join a query to a subquery. Each of these methods receive three arguments: the subquery, its table alias, and a Closure that defines the related columns:\n```javascript\nawait Builder()\n  .table('users')\n  .join('contacts', join =\u003e {\n    join\n      .on('users.id', '=', 'contacts.user_id')\n      .where('contacts.user_id', '\u003e', 5);\n    })\n  .get()\n```\n\n### Unions\nThe query builder also provides a quick way to \"union\" two queries together. For example, you may create an initial query and use the `union` method to union it with a second query:\n```javascript\nlet first = await Builder()\n  .table('users')\n  .whereNull('first_name')\n\nlet users = await Builder()\n  .table('users')\n  .whereNull('last_name')\n  .union(first)\n  .get()\n```\n\n\u003e The `unionAll` method is also available and has the same method signature as `union`.\n\n### Where Clauses\n**Simple Where Clauses**\n\nYou may use the `where` method on a query builder instance to add `where` clauses to the query. The most basic call to `where` requires three arguments. The first argument is the name of the column. The second argument is an operator, which can be any of the database's supported operators. Finally, the third argument is the value to evaluate against the column.\n\nFor example, here is a query that verifies the value of the \"votes\" column is equal to 100:\n```javascript\nlet users = await Builder()\n  .table('users')\n  .where('votes', '=', 100)\n  .get()\n```\nFor convenience, if you want to verify that a column is equal to a given value, you may pass the value directly as the second argument to the `where` method:\n```javascript\nlet users = await Builder()\n  .table('users')\n  .where('votes', 100)\n  .get()\n```\nYou may use a variety of other operators when writing a `where` clause:\n```javascript\nlet usersA = await Builder()\n  .table('users')\n  .where('votes', '\u003e=', 100)\n  .get()\n\nlet usersB = await Builder()\n  .table('users')\n  .where('votes', '\u003c\u003e', 100)\n  .get()\n\nlet usersC = await Builder()\n  .table('users')\n  .where('name', 'like', 'T%')\n  .get()\n```\nYou may also pass an array of conditions to the `where` function:\n```javascript\nlet users = await Builder()\n  .table('users')\n  .where([\n    ['status', '=', '1'],\n    ['subscribed', '\u003c\u003e', '1'],\n  ])\n  .get()\n```\n\n**Or Statements**\n\nYou may chain where constraints together as well as add or clauses to the query. The `orWhere` method accepts the same arguments as the `where` method:\n```javascript\nlet users = await Builder()\n  .table('users')\n  .where('votes', '\u003e', 100)\n  .orWhere('name', 'John')\n  .get()\n```\n\n**Additional Where Clauses**\n\n`whereBetween / orWhereBetween`\n\nThe `whereBetween` method verifies that a column's value is between two values:\n```javascript\nlet users = await Builder()\n  .table('users')\n  .whereBetween('votes', [1, 100])\n  .get()\n```\n\n`whereNotBetween / orWhereNotBetween`\n\nThe `whereNotBetween` method verifies that a column's value lies outside of two values:\n```javascript\nlet users = await Builder()\n  .table('users')\n  .whereNotBetween('votes', [1, 100])\n  .get()\n```\n\n`whereIn / whereNotIn / orWhereIn / orWhereNotIn`\n\nThe `whereIn` method verifies that a given column's value is contained within the given array:\n```javascript\nlet users = await Builder()\n  .table('users')\n  .whereIn('id', [1, 2, 3])\n  .get()\n```\n\nThe `whereNotIn` method verifies that the given column's value is not contained in the given array:\n```javascript\nlet users = await Builder()\n  .table('users')\n  .whereNotIn('id', [1, 2, 3])\n  .get()\n```\n\n`whereNull / whereNotNull / orWhereNull / orWhereNotNull`\n\nThe `whereNull` method verifies that the value of the given column is `NULL`:\n```javascript\nlet users = await Builder()\n  .table('users')\n  .whereNull('updated_at')\n  .get()\n```\n\nThe `whereNotNull` method verifies that the column's value is not `NULL`:\n```javascript\nlet users = await Builder()\n  .table('users')\n  .whereNotNull('updated_at')\n  .get()\n```\n\n`whereDate / whereMonth / whereDay / whereYear / whereTime`\n\nThe `whereDate` method may be used to compare a column's value against a date:\n```javascript\nlet users = await Builder()\n  .table('users')\n  .whereDate('created_at', '2016-12-31')\n  .get()\n```\n\nThe `whereMonth` method may be used to compare a column's value against a specific month of a year:\n```javascript\nlet users = await Builder()\n  .table('users')\n  .whereMonth('created_at', '12')\n  .get()\n```\n\nThe `whereDay` method may be used to compare a column's value against a specific day of a month:\n```javascript\nlet users = await Builder()\n  .table('users')\n  .whereDay('created_at', '31')\n  .get()\n```\n\nThe `whereYear` method may be used to compare a column's value against a specific year:\n```javascript\nlet users = await Builder()\n  .table('users')\n  .whereYear('created_at', '2016')\n  .get()\n```\n\nThe `whereTime` method may be used to compare a column's value against a specific time:\n```javascript\nlet users = await Builder()\n  .table('users')\n  .whereTime('created_at', '=', '11:20:45')\n  .get()\n```\n\n`whereColumn / orWhereColumn`\n\nThe `whereColumn` method may be used to verify that two columns are equal:\n```javascript\nlet users = await Builder()\n  .table('users')\n  .whereColumn('first_name', 'last_name')\n  .get()\n```\n\nYou may also pass a comparison operator to the method:\n```javascript\nlet users = await Builder()\n  .table('users')\n  .whereColumn('updated_at', '\u003e', 'created_at')\n  .get()\n```\n\nThe `whereColumn` method can also be passed an array of multiple conditions. These conditions will be joined using the and operator:\n```javascript\nlet users = await Builder()\n  .table('users')\n  .whereColumn([\n    ['first_name', '=', 'last_name'],\n    ['updated_at', '\u003e', 'created_at'],\n  ])\n  .get()\n```\n\n#### Parameter Grouping\nSometimes you may need to create more advanced where clauses such as \"where exists\" clauses or nested parameter groupings. The Laravel query builder can handle these as well. To get started, let's look at an example of grouping constraints within parenthesis:\n\n```javascript\nlet users = await Builder()\n  .table('users')\n  .where('name', '=', 'John')\n  .where(query =\u003e {\n    query\n      .where('votes', '\u003e', 100)\n      .orWhere('title', '=', 'Admin')\n  })\n  .get()\n```\n\nAs you can see, passing a `Closure` into the `where` method instructs the query builder to begin a constraint group. The `Closure` will receive a query builder instance which you can use to set the constraints that should be contained within the parenthesis group. The example above will produce the following SQL:\n\n```javascript\nselect * from users where name = 'John' and (votes \u003e 100 or title = 'Admin')\n```\n\n\u003e You should always group `orWhere` calls in order to avoid unexpected behavior when global scopes are applied.\n\n### Ordering, Grouping, Limit \u0026 Offset\n**orderBy**\n\nThe `orderBy` method allows you to sort the result of the query by a given column. The first argument to the `orderBy` method should be the column you wish to sort by, while the second argument controls the direction of the sort and may be either `asc` or `desc`:\n```javascript\nlet users = await Builder() \n  .table('users')\n  .orderBy('name', 'desc')\n  .get()\n```\n\n**latest / oldest**\n\nThe `latest` and `oldest` methods allow you to easily order results by date. By default, result will be ordered by the `created_at` column. Or, you may pass the column name that you wish to sort by:\n```javascript\nlet users = await Builder() \n  .table('users')\n  .latest()\n  .first()\n```\n\n**inRandomOrder**\n\nThe `inRandomOrder` method may be used to sort the query results randomly. For example, you may use this method to fetch a random user:\n```javascript\nlet users = await Builder() \n  .table('users')\n  .inRandomOrder()\n  .first()\n```\n\n**groupBy / having**\n\nThe `groupBy` and `having` methods may be used to group the query results. The having method's signature is similar to that of the where method:\n```javascript\nlet users = await Builder() \n  .table('users')\n  .groupBy('account_id')\n  .having('account_id', '\u003e', 100)\n  .get()\n```\n\nYou may pass multiple arguments to the `groupBy` method to group by multiple columns:\n```javascript\nlet users = await Builder() \n  .table('users')\n  .groupBy('first_name', 'status')\n  .having('account_id', '\u003e', 100)\n  .get()\n```\n\nFor more advanced `having` statements, see the `havingRaw` method.\n\n**skip / take**\n\nTo limit the number of results returned from the query, or to skip a given number of results in the query, you may use the `skip` and `take` methods:\n```javascript\nlet users = await Builder() \n  .table('users')\n  .skip(10)\n  .take(5)\n  .get()\n```\n\nAlternatively, you may use the `limit` and `offset` methods:\n```javascript\nlet users = await Builder() \n  .table('users')\n  .offset(10)\n  .limit(5)\n  .get()\n```\n\n### Inserts\nThe query builder also provides an `insert` method for inserting records into the database table. The `insert` method accepts an array of column names and values:\n```javascript\nlet users = await Builder() \n  .table('artists')\n  .insert({\n    ArtistId: 500,\n    Name: 'Euismod Pellentesque'\n  })\n```\n\nYou may even insert several records into the table with a single call to `insert` by passing an array of arrays. Each array represents a row to be inserted into the table:\n```javascript\nlet users = await Builder() \n  .table('artists')\n  .insert([\n    {\n      ArtistId: 501,\n      Name: 'Venenatis Elit'\n    },\n    {\n      ArtistId: 502,\n      Name: 'Justo Pellentesque'\n    },\n  ])\n```\n\nThe `insertOrIgnore` method will ignore duplicate record errors while inserting records into the database:\n```javascript\nlet users = await Builder() \n  .table('artists')\n  .insertOrIgnore([\n    {\n      ArtistId: 501,\n      Name: 'Venenatis Elit'\n    },\n    {\n      ArtistId: 502,\n      Name: 'Justo Pellentesque'\n    },\n  ])\n```\n\n**Auto-Incrementing IDs**\n\nIf the table has an auto-incrementing id, use the `insertGetId` method to insert a record and then retrieve the ID:\n```javascript\nlet users = await Builder() \n  .table('artists')\n  .insertGetId({\n    ArtistId: 503,\n    Name: 'Egestas Inceptos'\n  })\n```\n\n### Updates\nIn addition to inserting records into the database, the query builder can also update existing records using the `update` method. The `update` method, like the `insert` method, accepts an array of column and value pairs containing the columns to be updated. You may constrain the `update` query using `where` clauses:\n```javascript\nlet artists = await Builder() \n  .table('artists')\n  .table('artists')\n  .where('ArtistId', 1)\n  .update({\n    Name: 'John Doe'\n  })\n```\n\n**Update Or Insert**\n\nSometimes you may want to update an existing record in the database or create it if no matching record exists. In this scenario, the `updateOrInsert` method may be used. The `updateOrInsert` method accepts two arguments: an array of conditions by which to find the record, and an array of column and value pairs containing the columns to be updated.\n\nThe `updateOrInsert` method will first attempt to locate a matching database record using the first argument's column and value pairs. If the record exists, it will be updated with the values in the second argument. If the record can not be found, a new record will be inserted with the merged attributes of both arguments:\n```javascript\nlet artists = await Builder() \n  .table('artists')\n  .updateOrInsert(\n    {\n      ArtistId: 506\n    },\n    {\n      Name: 'Polymer'\n    }\n  )\n```\n\n#### Increment \u0026 Decrement\nThe query builder also provides convenient methods for incrementing or decrementing the value of a given column. This is a shortcut, providing a more expressive and terse interface compared to manually writing the `update` statement.\n\nBoth of these methods accept at least one argument: the column to modify. A second argument may optionally be passed to control the amount by which the column should be incremented or decremented:\n```javascript\nlet artistsA = await Builder() \n  .table('artists')\n  .increment('votes')\n\nlet artistsB = await Builder() \n  .table('artists')\n  .increment('votes', 5)\n\nlet artistsC = await Builder() \n  .table('artists')\n  .decrement('votes')\n\nlet artistsD = await Builder() \n  .table('artists')\n  .decrement('votes', 5)\n\n```\n\nYou may also specify additional columns to update during the operation:\n```javascript\nlet artists = await Builder() \n  .table('artists')\n  .increment('votes', 1, {name: 'John'})\n```\n\n### Deletes\nThe query builder may also be used to delete records from the table via the `delete` method. You may constrain `delete` statements by adding `where` clauses before calling the `delete` method:\n```javascript\nawait Builder() \n  .table('artists')\n  .delete()\n\nawait Builder() \n  .table('artists')\n  .where('ArtistId', 505)\n  .delete()\n```\n\nIf you wish to truncate the entire table, which will remove all rows and reset the auto-incrementing ID to zero, you may use the `truncate` method:\n```javascript\nawait Builder() \n  .table('artists')\n  .truncate()\n```\n\n## Contributing\n\n\u003e Crane is platform-agnostic, which means it can be used for a web app, and it can be extended for other drivers like PostgreSQL or MySQL by adding Grammar and Connection.\n\nWe appreciate feedback and contribution to this repo! Before you get started, please see the following:\n\n- [This repo's contribution guide](CONTRIBUTING.md)\n\n## Support + Feedback\n\n- Use [Issues](https://github.com/adhyapranata/crane/issues) for code-level support\n- Use [Mail](mailto://adhyapranata@wingtrail.com) for usage, questions, specific cases\n\n\n## Thank You!\n\n- [Laravel](https://laravel.com/docs/6.x/queries) as the primary reference of this library\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadhyapranata%2Fcrane","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadhyapranata%2Fcrane","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadhyapranata%2Fcrane/lists"}