Page 1 of 1

Separate persistence layer

Posted: 01 May 2024, 05:50
by imralav
Hello guys,

do you have any patterns for wrapping the DB calls into separate layer of classes instead of doing it all from the main Game class? It has those pesky static protected functions to work with the DB and I am not fluent enough in PHP to come up with something. I want to get those DB calls outside of main class to declutter it a bit.

Best regards
Tomasz

Re: Separate persistence layer

Posted: 01 May 2024, 14:00
by RicardoRix
You can create your own class and just inherit / extends APP_GameClass. Now you're free to use all the BGA DB functions.

I have something I developed called DBSQL and DBTables in my AuntiieMildred project. modules folder. Map it directly to your own tables (DBTables) and expects an auto incrementing id.

Re: Separate persistence layer

Posted: 02 May 2024, 05:40
by imralav
Ricardo, do you have this AuntiieMildred project uploaded somewhere, on GitHub maybe? I want to take a peek if you don't mind.

Re: Separate persistence layer

Posted: 02 May 2024, 09:36
by RicardoRix
You can find it on BGA Studio (as with all the other projects), use the project page and FTP to get it.
It's my usual hack and slash code style, but does the job for me.

I don't use github, but there are a few developers that have shared a good deal of their code base on github.
https://github.com/topics/boardgamearena

Re: Separate persistence layer

Posted: 02 May 2024, 10:02
by imralav
Oh, I had no idea that we can access other developer's games. I just setup the FTP as I would for myself, but just using different remote path?

Re: Separate persistence layer

Posted: 02 May 2024, 11:53
by RicardoRix
If you can find the Get read-only access button on the projects page, and boom just automatically appears in your FTP root folder.

Re: Separate persistence layer

Posted: 02 May 2024, 12:17
by imralav
It works, that's amazing, thank you. I'll check it out and come back with questions if I have any. Papa bless.

Re: Separate persistence layer

Posted: 02 May 2024, 12:20
by imralav
Oooh, I get it, now I understand why I was so confused. You only extend this APP_GameClass for those SQL related methods, you don't replace the instance of GameClass itself, which I thought you were doing. Smart.

Re: Separate persistence layer

Posted: 02 May 2024, 17:54
by Tisaac
imralav wrote: 01 May 2024, 05:50 Hello guys,

do you have any patterns for wrapping the DB calls into separate layer of classes instead of doing it all from the main Game class? It has those pesky static protected functions to work with the DB and I am not fluent enough in PHP to come up with something. I want to get those DB calls outside of main class to declutter it a bit.

Best regards
Tomasz
You may want to check my boilerplate to see a modular approach : https://github.com/bga-devs/tisaac-boilerplate

Re: Separate persistence layer

Posted: 03 May 2024, 04:39
by imralav
Tisaac wrote: 02 May 2024, 17:54 You may want to check my boilerplate to see a modular approach : https://github.com/bga-devs/tisaac-boilerplate
Man, this is incredible and exactly what I've been looking for. Coming from Java, I've been missing a decent approach to separate concerns between the classes.