{"id":13706707,"url":"https://github.com/r-dbi/odbc","last_synced_at":"2025-05-15T08:08:46.786Z","repository":{"id":37663490,"uuid":"63273973","full_name":"r-dbi/odbc","owner":"r-dbi","description":"Connect to ODBC databases (using the DBI interface)","archived":false,"fork":false,"pushed_at":"2025-03-27T15:03:17.000Z","size":17193,"stargazers_count":396,"open_issues_count":69,"forks_count":110,"subscribers_count":29,"default_branch":"main","last_synced_at":"2025-04-14T12:18:20.993Z","etag":null,"topics":["database","odbc","r"],"latest_commit_sha":null,"homepage":"https://odbc.r-dbi.org/","language":"C++","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/r-dbi.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":".github/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}},"created_at":"2016-07-13T19:32:07.000Z","updated_at":"2025-03-27T14:54:39.000Z","dependencies_parsed_at":"2024-01-16T18:37:03.122Z","dependency_job_id":"babb256c-4448-4928-b068-e32d43eddf8f","html_url":"https://github.com/r-dbi/odbc","commit_stats":{"total_commits":1239,"total_committers":47,"mean_commits":"26.361702127659573","dds":"0.36077481840193704","last_synced_commit":"bd6686766a503dc69040d19e99c03a9ad3a73967"},"previous_names":[],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-dbi%2Fodbc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-dbi%2Fodbc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-dbi%2Fodbc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-dbi%2Fodbc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/r-dbi","download_url":"https://codeload.github.com/r-dbi/odbc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248877967,"owners_count":21176244,"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":["database","odbc","r"],"created_at":"2024-08-02T22:01:06.025Z","updated_at":"2025-04-14T12:18:27.634Z","avatar_url":"https://github.com/r-dbi.png","language":"C++","funding_links":[],"categories":["Database Management","C++"],"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, echo = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"README-\",\n  eval = as.logical(Sys.getenv(\"ODBC_EVAL_README\", \"false\"))\n)\n```\n\n# odbc \u003ca href=\"https://odbc.r-dbi.org\"\u003e\u003cimg src=\"man/figures/logo.png\" align=\"right\" height=\"138\" alt=\"odbc website\" /\u003e\u003c/a\u003e\n\u003c!-- badges: start --\u003e\n[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/)\n[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/odbc)](https://cran.r-project.org/package=odbc)\n[![R-CMD-check](https://github.com/r-dbi/odbc/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-dbi/odbc/actions/workflows/R-CMD-check.yaml)\n[![Codecov test coverage](https://codecov.io/gh/r-dbi/odbc/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-dbi/odbc?branch=main)\n\u003c!-- badges: end --\u003e\n\nThe goal of the odbc package is to provide a [DBI](https://dbi.r-dbi.org/)-compliant interface to [ODBC](https://learn.microsoft.com/en-us/sql/odbc/microsoft-open-database-connectivity-odbc) drivers. This makes it easy to connect databases such as [SQL Server](https://www.microsoft.com/en-us/sql-server/), Oracle, [Databricks](https://www.databricks.com/), and Snowflake.\n\nThe odbc package is an alternative to\n[RODBC](https://cran.r-project.org/package=RODBC) and [RODBCDBI](https://cran.r-project.org/package=RODBCDBI) packages, and is typically much faster. See `vignette(\"benchmarks\")` to learn more.\n\n## Overview\n\nThe odbc package is one piece of the R interface to databases with support for ODBC:\n\n```{r whole-game, eval = TRUE, echo = FALSE}\n#| fig-alt: \u003e \n#|   A diagram containing four boxes with arrows linking each pointing left to \n#|   right. The boxes read, in order, \"R interface,\" \"driver manager,\" \n#|   \"ODBC driver,\" and \"DBMS.\" The left-most box, R interface, contains \n#|   three smaller components, labeled \"dbplyr,\" \"DBI,\" and \"odbc.\"\nknitr::include_graphics(\"man/figures/whole-game.png\")\n```\n\nSupport for a given DBMS is provided by an **ODBC driver**, which defines how to interact with that DBMS using the standardized syntax of ODBC and SQL. Drivers can be downloaded from the DBMS vendor or, if you're a Posit customer, using the [professional drivers](https://docs.posit.co/pro-drivers/).\n\nDrivers are managed by a **driver manager**, which is responsible for configuring driver locations, and optionally named **data sources** that describe how to connect to a specific database. Windows is bundled with a driver manager, while MacOS and Linux require installation of [unixODBC](https://www.unixodbc.org/). Drivers often require some manual configuration; see `vignette(\"setup\")` for details.\n\nIn the **R interface**, the [DBI package](https://dbi.r-dbi.org/) provides a front-end while odbc implements a back-end to communicate with the driver manager. The odbc package is built on top of the\n[nanodbc](https://nanodbc.github.io/nanodbc/) C++ library. To interface with DBMSs using R and odbc:\n\n```{r r-interface, eval = TRUE, echo = FALSE}\n#| fig-alt: \u003e\n#|   A high-level workflow for using the R interface in 3 steps. \n#|   In step 1, configure drivers and data sources, the functions \n#|   odbcListDrivers() and odbcListDataSources() help to interface with the \n#|   driver manager. In step 2, the dbConnect() function, called with the \n#|   first argument odbc(), connects to a database using the specified ODBC \n#|   driver to create a connection object \"con.\" Finally, in step 3, that \n#|   connection object can be passed to various functions to retrieve \n#|   information on database structure, iteratively develop queries, and \n#|   query data objects.\nknitr::include_graphics(\"man/figures/r-interface.png\")\n```\n\nYou might also use the [dbplyr package](https://dbplyr.tidyverse.org/) to automatically generate SQL from your dplyr code.\n\n## Installation \n\nInstall the latest release of odbc from CRAN with the following code:\n\n```r\ninstall.packages(\"odbc\")\n```\n\nTo get a bug fix or to use a feature from the development version, you can install the development version of odbc from GitHub:\n\n```r\n# install.packages(\"pak\")\npak::pak(\"r-dbi/odbc\")\n```\n\n## Usage\n\nTo use odbc, begin by creating a database connection, which might look something like this:\n\n```{r}\n#| eval: false\nlibrary(DBI)\n\ncon \u003c- dbConnect(\n  odbc::odbc(),\n  driver = \"SQL Server\",\n  server = \"my-server\",\n  database = \"my-database\",\n  uid = \"my-username\",\n  pwd = rstudioapi::askForPassword(\"Database password\")\n)\n```\n\n(See `vignette(\"setup\")` for examples of connecting to a variety of databases.)\n\n`dbListTables()` is used for listing all existing tables in a database.\n\n```{r}\n#| eval: false\ndbListTables(con)\n```\n\n`dbReadTable()` will read a full table into an R `data.frame()`.\n\n```{r}\n#| eval: false\ndata \u003c- dbReadTable(con, \"flights\")\n```\n\n`dbWriteTable()` will write an R `data.frame()` to an SQL table.\n\n```{r}\n#| eval: false\ndbWriteTable(con, \"iris\", iris)\n```\n\n`dbGetQuery()` will submit a SQL query and fetch the results:\n\n```{R}\n#| eval: false\ndf \u003c- dbGetQuery(\n  con,\n  \"SELECT flight, tailnum, origin FROM flights ORDER BY origin\"\n)\n```\n\nIt is also possible to submit the query and fetch separately with `dbSendQuery()` and `dbFetch()`. This allows you to use the `n` argument to `dbFetch()` to iterate over results that would otherwise be too large to fit in memory.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-dbi%2Fodbc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fr-dbi%2Fodbc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-dbi%2Fodbc/lists"}