{"id":31790758,"url":"https://github.com/daranzolin/sqltargets","last_synced_at":"2025-10-10T16:29:41.933Z","repository":{"id":233060867,"uuid":"785918196","full_name":"daranzolin/sqltargets","owner":"daranzolin","description":"targets extension for SQL queries","archived":false,"fork":false,"pushed_at":"2024-10-02T16:29:56.000Z","size":165,"stargazers_count":40,"open_issues_count":7,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-10T16:29:39.847Z","etag":null,"topics":["pipeline","r","rstats","sql","targets","workflow"],"latest_commit_sha":null,"homepage":"https://daranzolin.github.io/sqltargets/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daranzolin.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-04-12T22:56:21.000Z","updated_at":"2025-10-06T09:43:51.000Z","dependencies_parsed_at":"2024-04-22T19:01:57.812Z","dependency_job_id":"8ea91855-d1ae-4a81-9269-2834a3eea42c","html_url":"https://github.com/daranzolin/sqltargets","commit_stats":null,"previous_names":["daranzolin/sqltargets"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/daranzolin/sqltargets","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daranzolin%2Fsqltargets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daranzolin%2Fsqltargets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daranzolin%2Fsqltargets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daranzolin%2Fsqltargets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daranzolin","download_url":"https://codeload.github.com/daranzolin/sqltargets/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daranzolin%2Fsqltargets/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279004707,"owners_count":26083750,"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-10-10T02:00:06.843Z","response_time":62,"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":["pipeline","r","rstats","sql","targets","workflow"],"created_at":"2025-10-10T16:29:37.622Z","updated_at":"2025-10-10T16:29:41.926Z","avatar_url":"https://github.com/daranzolin.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# sqltargets \u003cimg src='man/figures/logo.png' align=\"right\" height=\"139\" /\u003e\n\n\u003c!-- badges: start --\u003e\n[![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)\n[![R-CMD-check](https://github.com/daranzolin/sqltargets/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/daranzolin/sqltargets/actions/workflows/R-CMD-check.yaml)\n[![CRAN status](https://www.r-pkg.org/badges/version/sqltargets)](https://CRAN.R-project.org/package=sqltargets)\n[![](https://cranlogs.r-pkg.org/badges/sqltargets)](https://cran.r-project.org/package=sqltargets)\n[![R Targetopia](https://img.shields.io/badge/R_Targetopia-member-blue?style=flat\u0026labelColor=gray)](https://wlandau.github.io/targetopia/)\n\n\u003c!-- badges: end --\u003e\n\nsqltargets makes it easy to integrate SQL files within your [targets workflows.](https://github.com/ropensci/targets) The shorthand `tar_sql()` creates two targets: (1) the ‘upstream’ SQL file; and (2) the ‘downstream’ result of the query. Dependencies can be specified by calling `tar_load()` within SQL comments. The template engine can be specified using the `sqltargets.template_engine` option (either 'glue' or 'jinjar').\n\n## Installation\n\nYou can install sqltargets from CRAN with:\n\n```r\ninstall.packages(\"sqltargets\")\n```\n\nYou can install the development version of sqltargets with:\n\n``` r\nremotes::install_github(\"daranzolin/sqltargets)\n```\n\n## Demo\n\nSee the [sqltargets-demo repository](https://github.com/daranzolin/sqltargets-demo) for a reproducible demonstration.\n\n\n## Dependencies\n\nUse `tar_load` or `targets::tar_load` within a SQL comment to indicate query \ndependencies. Check the dependencies of any query with `tar_sql_deps`.\n\n```{r}\nlibrary(sqltargets)\nlines \u003c- c(\n   \"-- !preview conn=DBI::dbConnect(RSQLite::SQLite())\",\n   \"-- targets::tar_load(data1)\",\n   \"-- targets::tar_load(data2)\",\n   \"select 1 AS my_col\",\n   \"\"\n )\n query \u003c- tempfile()\n writeLines(lines, query)\n tar_sql_deps(query)\n```\n\n## Parameters\n\nYou can pass parameters (presumably from another object in your targets project) to `tar_sql()` using one of two 'template engines': [glue](https://github.com/tidyverse/glue) or 'Jinja' (courtesy of [the 'jinjar' package.)](https://github.com/davidchall/jinjar)  \n\nSet the 'template engine' with `sqltargets_option_set(\"sqltargets.template_engine\", \"jinjar\")`. ('glue' is the default.)\n\nWith glue:\n\n`query.sql`\n\n```sql\n-- !preview conn=DBI::dbConnect(RSQLite::SQLite())\n-- tar_load(params)\nselect id\nfrom table\nwhere age \u003e {age_threshold}\n```\n\n`_targets.R`\n\n```{r eval = FALSE}\nlibrary(targets)\nlibrary(sqltargets)\nlist(\n  tar_target(params, list(age_threshold = 30)),\n  tar_sql(report, path = \"query.sql\", params = params)\n  )\n```\n\nWith 'Jinja':\n\n`query.sql`\n\n```sql\n-- !preview conn=DBI::dbConnect(RSQLite::SQLite())\n-- tar_load(payment_methods)\nselect\norder_id,\n{% for payment_method in params.payment_methods %}\nsum(case when payment_method = '{{payment_method}}' then amount end) as {{payment_method}}_amount\n{% if not loop.is_last %},{% endif %}\n{% endfor %}\nfrom payments\ngroup by 1\n```\n\n`_targets.R`\n\n```{r eval = FALSE}\nlibrary(targets)\nlibrary(sqltargets)\n\nsqltargets_option_set(\"sqltargets.template_engine\", \"jinjar\")\n\nlist(\n  tar_target(payment_methods, list(payment_methods = c(\"bank_transfer\", \"credit_card\", \"gift_card\"))),\n  tar_sql(report, path = \"query.sql\", params = payment_methods)\n  )\n```\n\nNote that `loop.is_last` differs from typical Jinja (`loop.last`). Refer to [this 'jinjar' vignette](https://davidchall.github.io/jinjar/articles/template-syntax.html) for other syntactical differences.\n\n![](inst/tar_glimpse.png)\n\n## Code of Conduct\n\nPlease note that the sqltargets project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.\n\n## Acknowledgement\n\nMuch of the code has been adapted from [the excellent tarchetypes package.](https://github.com/ropensci/tarchetypes) Special \nthanks to the authors and Will Landau in particular for revolutionizing data pipelines in R.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaranzolin%2Fsqltargets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaranzolin%2Fsqltargets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaranzolin%2Fsqltargets/lists"}