Giter VIP home page Giter VIP logo

easydb's Issues

Wrap in a new class

I think we shouldn't build methods for class "DBIConnection". Instead db_connect() should create a class "easydb" and we'll have "easydb" methods.

describe()

quite convenient :

summary.DBIConnection <- function(object, ...){
  cat(crayon::cyan("OBJECT"), "\n",sep="")
  print(object)
  cat("\n", crayon::cyan("TABLES"), "\n",sep="")
  print(DBI::dbListTables(object))
  cat("\n","use `str(object)` for details", "\n", sep="")
  
  cat("\n", crayon::cyan("DEFAULT summary"), "\n",sep="")
  summary.default(object,...)
}

str.DBIConnection <- function(object, ...){
  cat(crayon::cyan("OBJECT"), "\n",sep="")
  print(object)
  cat("\n", crayon::cyan("TABLES"), "\n",sep="")
  tables <- DBI::dbListTables(object)
  tables <- setNames(tables, tables)
  for(tbl in tables){
    cat("\n", crayon::yellow(tbl), "\n", sep="")
    error <- try(tibble::glimpse(object[[tbl]]),silent = TRUE)
    if(inherits(error,"try-error")) cat(error,"\n")
  }
  
  cat("\n", crayon::cyan("DEFAULT str"), "\n",sep="")
  invisible(utils:::str.default(object,...))
}

update ?

if we add a class to our easydb_tbl class to our tbl_lazy objects we can have a [.easydb_tbl method.

This can act a bit like data table, and := will work to "update where". But we skip all the sophisticated stuff, grouping etc...

view ?

Maybe would be good to have this here if not implemented in tibble. easydb already imports tibble.

view <- function(x, title = NULL, ...){
  UseMethod("view")
}

view.default <- tibble::view()

view.tbl_lazy <- function(x, title = NULL, n = 500, ...){
  if (is.null(title)) title <- rlang::expr_deparse(substitute(x)) # enexpr doesn't work in methods, see https://github.com/r-lib/rlang/issues/368
  View(dplyr::collect(head(x, n)), title, ...)
}

Maybe this could be used for connections instead of
#3

Fail to handle connection where schema needs to be specified

Reprex below.

library(easydb)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

## Try 1
drv <- DBI::dbDriver("Oracle")
con <- db_connect(
  drv,
  dbname = "my_db",
  username = "read",
  password = "read",
  schema = "my_schema"
)

con$my_tbl
#> Error in .oci.SendQuery(conn, statement, data = data, prefetch = prefetch,  : 
#>  ORA-00942: table or view does not exist

## Try 2
specs <- list(
  drv = DBI::dbDriver("Oracle"),
  dbname = "my_db",
  username = "read",
  password = "read"
)

con <- db_connect(specs)

my_tbl <- dbplyr::in_schema("my_schema", "my_tbl")

con$my_tbl
#> Error in .oci.SendQuery(conn, statement, data = data, prefetch = prefetch,  : 
#>  ORA-00942: table or view does not exist

# works
dplyr::tbl(con, my_tbl)

Created on 2019-09-02 by the reprex package (v0.2.1)

improve ?db_connect

it is wrong at the moment, in particular for PostgreSQL ?RPostgres::Postgres is not useful at all and user should do ?RPostgres::dbConnect,PqDriver-method``

It would be nice to have direct links to those too.

The package is broken

because we used this : getFromNamespace("db_has_table.DBIConnection", "dbplyr")

I'm not sure why we used a non exported function there but there should be an exported alternative

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.