support ourdb and postgresql backend #10
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Postgres support has been added on branch development_postgress in
heromodels/db/postgres.rs
, next to the existing ourdb implementation. Data is stored in postgres tables using a key-value setup. Table name is a bit altered (prefixed withmodel_
) to avoid collisions on keywoards in postgres. The first time a collection of a Model is accesses, the table is created and relevant indexes will be set up.An example
postgres_model_example
has been added to show how to work with postgres, its essentially a copy ofbasic_user_example
but with a postgres db instead of an ourdb, so only 1 line difference.Some minor changes have been made to the Index and Model trait definitions, and the required changes were made in the Model macro to make sure generated structs once again comply to these traits. Everything should just get the new code and work out of the box on the next compile (after pulling)
Note that since my original work on the DB, some "transaction" support was added. Since the logic in ourdb is just not doing anything, and the transaction interface itself is not supporting actual transaction logic, the
begin_transaction
method just returns an error, which seems more useful to a consumer then shipping a broken transaction implementation. Should this be fixed in the future, it will be fairly trivial to also add it to the postgres implementation.The postgres example can be run with a postgres exposed on localhost, with a postgres user with password
test123
. A simple way to do this is with a docker:docker run --name postgres -e POSTGRES_PASSWORD=test123 -d -p5432:5432 postgres
After running the example once, some data is left in the db which causes the next invocation to fail (since the example asserts on the amount of returned data). To clear the db:
docker exec -ti postgres psql -U postgres
Or recreate the docker
Branch merged to main