Title: | Connection wrapper to SQLite databases |
---|---|
Description: | sqliter helps users, mainly data munging practioneers, to organize their sql calls in a clean structure. It simplifies the process of extracting and transforming data into useful formats. |
Authors: | Wilson Freitas <[email protected]> |
Maintainer: | Wilson Freitas <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2025-03-05 02:45:55 UTC |
Source: | https://github.com/wilsonfreitas/sqliter |
sqliter helps users, mainly data munging practioneers, to organize their sql calls in a clean structure. It simplifies the process of extracting and transforming data into useful formats.
lists databases into path
databases(object, filter = "") ## S3 method for class 'sqliter' databases(object, filter = "")
databases(object, filter = "") ## S3 method for class 'sqliter' databases(object, filter = "")
object |
|
filter |
DBM <- sqliter(path='data') databases(DBM) databases(DBM, 'fu')
DBM <- sqliter(path='data') databases(DBM) databases(DBM, 'fu')
returns the paths of the given database
find_database(object, database) ## S3 method for class 'sqliter' find_database(object, database)
find_database(object, database) ## S3 method for class 'sqliter' find_database(object, database)
object |
|
database |
the SQLite database filename without extension |
## Not run: DBM <- sqliter(path=c("data", "another/project/data")) find_database(DBM, "dummydatabase") # "data/dummydatabase.db" ## End(Not run)
## Not run: DBM <- sqliter(path=c("data", "another/project/data")) find_database(DBM, "dummydatabase") # "data/dummydatabase.db" ## End(Not run)
Once you have a sqliter
database properly set you can execute queries into that database and get your data transformed.
By default this function returns a data.frame object, but if you transform your data you can get whatever you need.
query(object, ...) ## S3 method for class 'sqliter' query(object, database, query, post_proc = identity, index = 1, ...)
query(object, ...) ## S3 method for class 'sqliter' query(object, database, query, post_proc = identity, index = 1, ...)
object |
|
... |
additional arguments used by prepared queries |
database |
the SQLite database filename without extension |
query |
the query string |
post_proc |
a function to transform data, it receives a database and returns whatever you need. |
## Not run: DBM <- sqliter(path=c("data", "another/project/data")) ds <- query(DBM, "dummydatabase", "select count(*) from dummytable") ds <- query(DBM, "dummydatabase", "select * from dummytable where name = :name", name=c("Macunamima", "Borba Gato")) ds <- query(DBM, "dummydatabase", "select * from dummytable where name = :name", name=c("Macunamima", "Borba Gato"), post_proc=function(ds) { ds <- transform(ds, birthday=as.Date(birthday)) ds }) ## End(Not run)
## Not run: DBM <- sqliter(path=c("data", "another/project/data")) ds <- query(DBM, "dummydatabase", "select count(*) from dummytable") ds <- query(DBM, "dummydatabase", "select * from dummytable where name = :name", name=c("Macunamima", "Borba Gato")) ds <- query(DBM, "dummydatabase", "select * from dummytable where name = :name", name=c("Macunamima", "Borba Gato"), post_proc=function(ds) { ds <- transform(ds, birthday=as.Date(birthday)) ds }) ## End(Not run)
**query functions** are dynamic functions which connect to a database, execute queries in it and transform data.
Actually it is a decorator for query
function.
query
has 5 arguments.
The first argument is an instance of the sqliter
class and the second is the database name.
The call to a query function is executed like a method call to the sqliter
object through the $
operator.
The function name must have the following pattern: query_<database name without extension>
.
This call returns an query
function with the first 2 argument already set.
The first parameter is the sqliter
object on which the $
operator have been called and the second argument is extracted from the query function name, the name after the preffix query_
.
## Not run: DBM <- sqliter(path=c("data", "another/project/data")) DBM$query_dummydatabase("select count(*) from dummytable") ## End(Not run)
## Not run: DBM <- sqliter(path=c("data", "another/project/data")) DBM$query_dummydatabase("select count(*) from dummytable") ## End(Not run)
sqliter
object works pretty much like a database manager helping users to execute queries and transform data through a clean interface.
sqliter(path = ".", ...)
sqliter(path = ".", ...)
... |
arguments such as |
## Not run: DBM <- sqliter(path=c("data", "another/project/data"))
## Not run: DBM <- sqliter(path=c("data", "another/project/data"))