BareDB is a lightweight and easy-to-use C library for basic database operations. It allows you to add, read, update, and delete structs in a database file.
BareDB is designed to provide a simple yet powerful solution for basic database operations in C. It is open-source and released under the MIT License.
- Add structs to a database
- Read structs from a database
- Update structs in a database
- Delete structs at a specific index from a database
- More in the future (You can use .bin files)
- Not endian clean, so portability is an issue especially when you want to write in a little endian machine and read data in a big endian machine (or vice-versa) (Working on this issue)
BareDB streamlines basic database operations in C, offering a user-friendly, lightweight solution. With an intuitive interface, it simplifies adding, reading, updating, and deleting structs in a database file. Ideal for beginners, BareDB's minimalist design ensures efficiency, making it a valuable tool for fundamental database functions in C.
To use BareDB in your C project, follow these steps:
- Clone this repo:
git clone https://github.com/blhmr/BareDB.git
- Change directory and build to see an example of usage (
main.c
):
cd BareDB
make build
./main
- In case you to install the library as a default library on your system (Linux):
- For a static library:
gcc -c baredb.c -o libbaredb.o # Compile the Library
ar rcs libbaredb.a libbaredb.o
sudo cp libbaredb.so /usr/lib # Copy the Library
sudo ldconfig # Update Library Cache
sudo cp baredb.h /usr/include # Include Header Files
Usage in Programs:
#include <baredb.h>
int main(void) {
// Your program logic using BareDB functions
return 0;
}
gcc -o your_program your_program.c -lbaredb
- Clean:
make clean
Bellow is a simple program to insert a point struct into a "database.db" database:
#include "baredb.h"
#pragma packed 1
typedef struct {
int x;
int y;
} point;
int main(void) {
// Open the database
table_t table;
bare_open(&table, "database.db", sizeof(point));
// Create a point struct with specific values
point p = {.x = 5, .y = 10};
// Insert the point struct into the database
bare_insert(&table, &p);
// Close the database
bare_close(&table);
return 0;
}
Of course you can read main.c
to see how all the functions work!
See the examples directory for usage examples.
Contributions are welcome! Feel free to open issues, submit pull requests, or provide feedback.
BareDB is open-source software licensed under the MIT License.