Giter VIP home page Giter VIP logo

dbi.table's Introduction

dbi.table

Query database objects (e.g., tables and views) accessible over a DBI connection using data.table-like syntax. Access individual objects using dbi.table or attach an entire schema using dbi.attach.

Installation

devtools::install_github("kjellpk/dbi.table")

Usage

First, load the package.

library(dbi.table)

Open a DBI connection to the Chinook database included in the package.

db_path <- file.path(system.file(package = "dbi.table"),
                     "example_files",
                     "chinook_sqlite.sqlite")
chinook <- DBI::dbConnect(RSQLite::SQLite(), db_path)

Create a dbi.table using the Album table in the Chinook database.

(Album <- dbi.table(chinook, DBI::Id(table = "Album")))

## <chinook_sqlite> Album 
##  AlbumId                                 Title ArtistId
##    <int>                                <char>    <int>
##        1 For Those About To Rock We Salute You        1
##        2                     Balls to the Wall        2
##        3                     Restless and Wild        2
##        4                     Let There Be Rock        1
##        5                              Big Ones        3
## ---

The local object Album is a dbi.table, a data structure that generates and executes queries on the remote (SQLite) table Album. dbi.tables use the same syntax as data.tables. For example, the following command selects the AlbumId and Title fields from the remote table Album where AlbumId is less than 100 and equal to ArtistId.

(x <- Album[AlbumId < 100 & AlbumId == ArtistId, .(AlbumId, Title)])

## <chinook_sqlite> Album 
##  AlbumId                                 Title
##    <int>                                <char>
##        1 For Those About To Rock We Salute You
##        2                     Balls to the Wall
##       58                   Come Taste The Band

By default, the preview is the first 5 rows returned by the dbms (in this case SQLite). There are only 3 records that satify the query so all results were returned.

The local object x is not the data, rather it is another dbi.table corresponding to the specific query. Use empty square brackets ([]) or the as.data.table function to fetch the results set as a data.table.

x[]

##    AlbumId                                 Title
##      <int>                                <char>
## 1:       1 For Those About To Rock We Salute You
## 2:       2                     Balls to the Wall
## 3:      58                   Come Taste The Band

dbi.table's People

Contributors

kjellpk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.