MemoryManager
MemoryManager is the main class used to access data base. You need an object of this class to work on tables.
TinyDatabase header#
Be sure that the library header was included in your sketch
#include <TinyDatabase_Arduino.h>Work on tables#
Constructor#
MemoryManager()To create an object
MemoryManager mem;Erase all#
If it is a new project, be sure to clear all the EEPROM with
void clearAll()mem.clearAll();Table creation#
You can create easily a table by invoking CREATE_TABLE methods
int CREATE_TABLE(char* tableName, uint8_t capacity, uint8_t col, Column tableCol[])tableName: the name of your table - no more than 2 charcapacity: the maximum of data that the table can hold. If this value is attended the next data start override old data from the topcol: the number of columns for this tabletableCol: an array of columns structre. Its contain all table's columns with their name and type. Go to Column to know more.
returna status code. The creation can be aborted if capacity value exceeds 255 or memory is not available or something else. Check status code to know more.
Column allCols[] = {{"ag", "INT"}, {"rt", "FLOAT"}}; mem.CREATE_TABLE("EM", 15, 2, allCols);- We create firstly two columns named
agandrtof typesINTandFLOAT. Read more about TinyDatabase types - Then the table with name
EMof15as its capacity.
danger
Tables name and columns name cannot be more than 02 characters. Othwersie we cut off and take only the first two char. They follow variables name structure.
tip
- For table name you can use uppercase letters like EM or PT or underscore as last char like E_ or P_.
- And use lowercase letter for columns name like ag or hm.
Display meta data#
You can print in Serial monitor informations about the data base: meta data. It contains amount of data, tables informations, address where these informations are stored
void printMetaData()mem.printMetaData(); // open your serial monitorTable existence#
You can check if a table exists in the database if you know its name.
int ON(char* tableName)tableName: the name of the table you want to check
returna negative number (status code) if the table doesn't exist and a positive number if it exists (the address where this tables meta data are stored).
Set data#
There are two mains actions that can be done on a table: write or read. If you want to write or delete data on table:
TableData& TO(char* tableName)tableName: the name of table on what you want to work.
returna reference to private member of MemoryManager to allow you to chain methods after when setting data on this table. If table doesn't exist, it return an invalid object of TableData.
TableData t_data = mem.TO("EM");Get data#
In the cas where you want to get data from the table:
TableData& FROM(char* tableName)tableName: the name of table on what you want to work.
returna reference to private member of MemoryManager to allow you to chain methods after when getting data from this table. If table doesn't exist, it returns an invalid object of TableData.
TableData t_data = mem.FROM("EM");tip
TOandFROMmethods do the samething and has the same structure but it is more readable if you:- TO for
INSERT,UPDATE,DELETE,DELETE_ALLqueries; - FROM for
SELECT,SELECT_ALL, queries.
Useful methods#
Memory availability#
You can check if there is more memory available in the data base.
int isMemoryAvailable(int need)need: the amount of space.
returna status code. Check status code to know more.
int memAvailableStatus = mem.isMemoryAvailable(100); // open your serial monitorData size#
You can check the possible amount data stored in the database (sum of all capacity).
int size()int amount = mem.size();Amount of tables#
You can also check the number of tables
uint8_t nbTables()caution
You cannot create more than 255 tables in the database.