Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/HuangRicky/DBFactory
R package to manage database connections
https://github.com/HuangRicky/DBFactory
connection connection-pool database mysql odbc oracle r sqlserver
Last synced: 9 days ago
JSON representation
R package to manage database connections
- Host: GitHub
- URL: https://github.com/HuangRicky/DBFactory
- Owner: HuangRicky
- License: gpl-3.0
- Created: 2020-06-16T02:47:44.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-06-16T03:14:31.000Z (over 4 years ago)
- Last Synced: 2024-08-13T07:12:56.026Z (4 months ago)
- Topics: connection, connection-pool, database, mysql, odbc, oracle, r, sqlserver
- Language: R
- Size: 24.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - HuangRicky/DBFactory - R package to manage database connections (R)
README
# DBFactory
R package to manage database connections# Installation
To install this package, you can download or clone the file, R CMD INSTALL or use RStudio to open and install, or use devtools:
```
devtools::install_github("HuangRicky/DBFactory")
```# Setting Up DB Information
You can create a Database Definition data.frame first:
```
sample_db_info <- data.frame(name=c('DEV','PRD', 'XXX', 'LOCAL','LOCALMYSQL','LOCALEXPRESS','SB'),
type=c("sqlserver", 'oracle',"sqlserver",'sqlserver', 'mysql','sqlserver',
'sybaseiq'),
connstring=c('', NA,NA,NA,NA,NA,NA),
server=c("serveraddress1", 'serveraddress2',
'tcp:xxxxx.database.windows.net,1433','localhost,1433',
'localhost','localhost,14433',
'testserver;port=9903'),
initdb=c("A",NA,'XXX','XXX','TEACHING','TEACHING','SYBASEID'),
istrusted=c(T,F,F,F,F,F,F),
user=c("",'a1','XXX','xxx','user_1','user_1','user_2'),
pass=c("",NA,'','','','',''), stringsAsFactors = F)
```If you download source code and install, you can run the following to write to your source package.
```
jsonlite::write_json(sample_db_info, 'inst/extdata/dbdata.json', pretty=T, na='null')
```If you install the package already, you can directly change the json file in your Library location:
```
nowlibpath <- paste0(.Library,'/DBFactory/extdata/dbdata.json')
jsonlite::write_json(sample_db_info, nowlibpath, pretty=T, na='null')
```# Usage
```
library(DBFactory)
# to set default object:
set_default_dbobj("LOCALMYSQL")
set_default_dbobj("LOCALEXPRESS")# see MySQL:
DBFactory::set_default_dbobj("LOCALMYSQL")
run_query('select * from teaching.Table1')# see MSSQL:
DBFactory::set_default_dbobj("LOCALEXPRESS")
run_query('select * from TEACHING.dbo.Test1')```