- HTTP API, can be used via Postman or Thunder Client;
- Uses in-memory cache to improve throughput;
- PostgreSQL - the best database management system;
- ANSI C;
- Cmake config to build project by yourself;
Request | HTTP Method | Request body | Asnwer |
---|---|---|---|
/data | PUT | {data: string "any string data"} | id: string uuid |
/data?id=my_id | GET | {id: string my_id, data: string my_data} |
Before we proceed:
- Install the PostreSQL (author uses Ubuntu)
sudo apt install postgresql postgresql-contrib
- Install PostgreSQL library
sudo apt-get install libpq-dev
- Install Tarantool
- Download and install C client library and msgpuck library
- If you cant login into Posgress, then follow this guide
- Start PostreSQL service
sudo sudo service postgresql start
- Login into psql
sudo -u postgres psql
- Create new user
CREATE USER pico WITH PASSWORD 'pico';
- Create a new database:
CREATE DATABASE picodb;
- Grant the user permission to access the database:
GRANT ALL PRIVILEGES ON DATABASE picodb TO pico; ALTER USER pico CREATEDB; GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO pico;
- Exit from PostgreSQL
\q
- Login into PostgreSQL as user and enter password:
psql -U pico -d picodb
- Add extension for generating UUIDs
CREATE EXTENSION "uuid-ossp";
NOTE:
Default PostgreSQL port is 8080. It can be configured in pg_hba.conf file
- Run Tarantool:
tarantool
- Set listening port:
box.cfg{ listen = '8081' }
NOTE:
Remember this port. It will be used to communicate with Tarantool. Can be confugured in config.txt (located in project folder)
- Change password for admin:
box.schema.user.passwd('pass')
- Create space - Tarantool table:
s = box.schema.space.create('pico_tarantool') s:format({{name = 'id', type = 'string'},{name = 'data', type = 'string'}})--- s:create_index('primary',{type = 'hash', parts = {'id'}})
- Get space id
box.space.pico_tarantool.id
NOTE:
Remember this id. It will be used to store data in it. Can be confugured in config.txt (located in project folder)
- Project main folder
-src
- main.c
- ...
CMakeLists.txt
config.txt
Readme.md
- Create build folder
mkdir build
- Configure cmake
cmake -B ./build -S .
NOTE:
Execute this command in folder, where CMakeLists.txt is located
- Change dir to build
cd ./build
- Run cmake
cmake ../CMakeLists.txt
- Run make
make
- Run compiled file pico with flag -f /path/to/config.txt
./pico -f ../config.txt
- Just use Postaman or Thunder Client. Create and send requests, guiding by HTTP data shema provided before.
- Enjoy :)
PUT request: JSON with spaces and will not work for Tarantool, while in PSQL stores correctly.FixedIf Tarantool goes offline while server is on - unexpected behavior.Fixed.- If PostgreSQL goes offline while server is on - unexpected behavior. Note: Server responses with PSQL error.
- If you face any bugs and glitches - be welcome to make Pull Request!
- Proof of concept
- MVP
- Add HTTP validation
- Cover MVP with test
- Make better query parameters handler
- Write func, that creates space in Tarantool, if space intially doesn't exist
- Add pthread support
- Check connection to PostgreSQL and Tarantool in separate threads
- Make cache asynchronous
- Cover code with test
- More stuff to do