MyNixOS website logo
Description

Connection wrapper to SQLite databases.

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.

sqliter

sqliter takes out the misery of your life helping you with SQLite queries without turing your code into a mess. Once you have many SQLite files to handle it simplifies your query calls by structuring the way you connect to your files, the databases.

Let's suppose you have some SQLite files spread on your computer. Some files you are working on now, and some others you have worked in other projects before. The standard approach would be copy the files into your new project or point to the files wherever they are. For those files you would simply create their connections, execute your queries creating a brand new data.frame and transform your data to get your job done.

When you have many files, you find yourself creating a bunch of annoying repeated code. I don't like repeated code, it smells bad and I take seriously the DRY principle. That is the reason why I created sqliter, to take away this misery of my life.

Install

Use devtools.

Introduction

In order to use sqliter you must declare the path where your SQLite files are hidden.

DBM <- sqliter(path=c('data', '../project2/data', '/path/to/project3/data'))

and query the databases.

ds <- DBM$query_database_dummy('select count(*) from dummytable')

where database_dummy is the name of SQLite file, without extension, lying inside some directory declared in the path. So, it should stand for data/database_dummy.db, ../project2/data/database_dummy.db or /path/to/project3/data/database_dummy.db.

If you have multiple files with the same name the priority is given accordingly the path order, exactly the same way shells like bash and csh do. Then, in our example, data/database_dummy.db would be the selected database.

The returned object, ds, is a data.frame with a column named count(*). The column names can be manipulated like any other sql call, appending a label after the variable.

Prepared queries

For parameterized queries we have prepared queries. You simply create queries with placeholders for the parameters and fulfill its values passing additional arguments to query_* function.

ds <- DBM$query_database_dummy('select name, country from dummytable where name = :name',
      name='Macunaima')

Note the placeholder :name, it is related to the argument name='Macunaima'. These arguments accept multiple values like name=c('Macunaima', 'Borba Gato'). The above example would return a data.frame with two columns named name and country.

Trasforming data

You can get your data transformed the way you want by using the argument post_proc. This argument must have a function which expects to receive a data.frame and returns whatever you want. I usually use post_proc for renaming columns and converting strings into datetime objects.

ds <- DBM$query_database_dummy('select birthday, name, country from dummytable where name = :name',
	name='Macunaima', post_proc=function(ds) {
		ds <- transform(ds, Birthday=as.Date(birthday, format='%d/%m/%Y'))
		ds
	})

Disclaimer

sqliter is deeply intended to research purposes, mainly data munging. I understand that by no means it should be used in any kind of production code.

Metadata

Version

0.1.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows