moodymudskipper / easydb Goto Github PK
View Code? Open in Web Editor NEWDBI and dplyr wrappers to write to DB, fetch and run data manipulation operations on server side.
DBI and dplyr wrappers to write to DB, fetch and run data manipulation operations on server side.
I don't want to support partial matching but partial matching is associated with $
.
If column not found it would be nice to check if partial matching would have worked, and if so, have the error inform the user that partial matchng doesn't work and that if he means "this table" he should ask for it explicitly.
I think we shouldn't build methods for class "DBIConnection". Instead db_connect()
should create a class "easydb" and we'll have "easydb" methods.
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,...))
}
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...
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
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)
foo
by con$foo
when relevantit 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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.