support ourdb and postgresql backend #10

Open
opened 2025-07-30 07:56:20 +00:00 by despiegk · 3 comments
Owner
  • indexes support string, int
  • postgresql & ourdb backend
  • best at runtime but if not can be at compile time with a flag or so
- indexes support string, int - postgresql & ourdb backend - best at runtime but if not can be at compile time with a flag or so
lee was assigned by despiegk 2025-07-30 07:56:24 +00:00
Member

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 with model_) 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 of basic_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.

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 with `model_`) 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 of `basic_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.
Member

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

DROP TABLE model_user;
DROP TABLE model_comment;
exit

Or recreate the docker

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` ```sql DROP TABLE model_user; DROP TABLE model_comment; exit ``` Or recreate the docker
Member

Branch merged to main

Branch merged to main
timur was assigned by despiegk 2025-08-04 07:39:56 +00:00
despiegk added this to the now milestone 2025-08-04 07:40:09 +00:00
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: herocode/db#10
No description provided.