|
1 | | -# bux-sqlite |
2 | | -Wrapper classes and utilities of the original sqlite3 CAPI |
| 1 | + |
| 2 | +## Table of Contents |
| 3 | + |
| 4 | + * [Rationale](#rationale) |
| 5 | + * [API Summary](#api-summary) |
| 6 | + * [Recurring Types and Their Safe Counterparts](#recurring-types-and-their-safe-counterparts) |
| 7 | + * [Installation](#installation) |
| 8 | + * [in <a href="https://archlinux.org/" rel="nofollow">ArchLinux</a>](#in-archlinux) |
| 9 | + * [from github in any of <a href="https://distrowatch.com/" rel="nofollow">Linux distros</a>](#from-github-in-any-of-linux-distros) |
| 10 | + |
| 11 | +*(Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc))* |
| 12 | + |
| 13 | +## Rationale |
| 14 | + |
| 15 | +The idea is to minimize boilerplate code when doing the same things using native [SQLite API](https://www.sqlite.org/capi3ref.html). Only recurring usages are wrapped into helper classes or plain functions. Mixed uses of this module and the native API are expected. Always prefer `bux::C_SQLite`, `bux::C_SQLiteStmt` over `sqlite3*`, `sqlite3_stmt*` and you will be fine. |
| 16 | + |
| 17 | +## API Summary |
| 18 | + |
| 19 | +### Recurring Types and Their Safe Counterparts |
| 20 | + |
| 21 | +| Original Type | Wrapper Class | |
| 22 | +|:-------------:|:--------------| |
| 23 | +| `sqlite3*` | `bux::C_SQLite` | |
| 24 | +| `sqlite3_stmt*` | `bux::C_SQLiteStmt` | |
| 25 | + |
| 26 | +1. The right colum (_class type_) of each row above can be cast to the left column (_native SQLite pointer type_) implicitly & _safely_. |
| 27 | +2. `bux::C_SQLite` can only be constructed by a valid SQLite databse file name. |
| 28 | +3. `bux::C_SQLiteStmt` is contructed by passing a `bux::C_SQLite` instance and a SQL statement. And it is the recommended way to bind SQL arguments by calling native `sqlite3_bind_\w+()` functions before its own `execute()` method. |
| 29 | + |
| 30 | +## Installation |
| 31 | + |
| 32 | +### in [ArchLinux](https://archlinux.org/) |
| 33 | + |
| 34 | +1. Make sure you have installed [`yay`](https://aur.archlinux.org/packages/yay/) or any other [pacman wrapper](https://wiki.archlinux.org/index.php/AUR_helpers). |
| 35 | +2. `yay -S bux-sqlite` to install. `bux` is also installed with it. |
| 36 | +3. `yay -Ql bux-sqlite` to see the installed files: |
| 37 | + |
| 38 | + ~~~bash |
| 39 | + bux-mariadb-client /usr/ |
| 40 | + bux-mariadb-client /usr/include/ |
| 41 | + bux-mariadb-client /usr/include/bux/ |
| 42 | + bux-mariadb-client /usr/include/bux/oo_mariadb.h |
| 43 | + bux-mariadb-client /usr/lib/ |
| 44 | + bux-mariadb-client /usr/lib/libbux-mariadb-client.a |
| 45 | + bux-mariadb-client /usr/share/ |
| 46 | + bux-mariadb-client /usr/share/licenses/ |
| 47 | + bux-mariadb-client /usr/share/licenses/bux-mariadb-client/ |
| 48 | + bux-mariadb-client /usr/share/licenses/bux-mariadb-client/LICENSE |
| 49 | + ~~~ |
| 50 | + |
| 51 | +4. Include the sole header file by prefixing the header name with `bux/`: |
| 52 | + |
| 53 | + ~~~c++ |
| 54 | + #include <bux/oo_sqlite.h> |
| 55 | + ~~~ |
| 56 | + |
| 57 | + *p.s.* Compiler is expected to search `/usr/include` by default. |
| 58 | +5. If directly using `gcc` or `clang` is intended, the required compiler flags are `-lbux-sqlite -lbux` |
| 59 | + |
| 60 | +### from github in any of [Linux distros](https://distrowatch.com/) |
| 61 | + |
| 62 | +1. Make sure you have installed `cmake` `make` `gcc` `git` `fmt` `sqlite`, or the likes. Known package names in different distros/package-managers: |
| 63 | + | Distro/PkgMngr | Package Name | |
| 64 | + |:----------------:|:------------:| |
| 65 | + | ArchLinux/yay | `fmt`, `sqlite` | |
| 66 | + | Fedora/dnf | `fmt-devel`, `sqlite-devel` | |
| 67 | + |
| 68 | +2. ~~~bash |
| 69 | + git clone https://github.com/buck-yeh/bux-sqlite.git |
| 70 | + cd bux-sqlite |
| 71 | + cmake -D FETCH_DEPENDEES=1 -D DEPENDEE_ROOT=_deps . |
| 72 | + make -j |
| 73 | + ~~~ |
| 74 | + |
| 75 | +3. Include `include/bux/oo_sqlite.h` and link with `src/libbux-sqlite.a` |
0 commit comments