Separate persistence layer

Game development with Board Game Arena Studio
Post Reply
imralav
Posts: 44
Joined: 02 February 2024, 08:56

Separate persistence layer

Post 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
User avatar
RicardoRix
Posts: 2548
Joined: 29 April 2012, 23:43

Re: Separate persistence layer

Post 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.
imralav
Posts: 44
Joined: 02 February 2024, 08:56

Re: Separate persistence layer

Post 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.
User avatar
RicardoRix
Posts: 2548
Joined: 29 April 2012, 23:43

Re: Separate persistence layer

Post 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
imralav
Posts: 44
Joined: 02 February 2024, 08:56

Re: Separate persistence layer

Post 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?
User avatar
RicardoRix
Posts: 2548
Joined: 29 April 2012, 23:43

Re: Separate persistence layer

Post 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.
imralav
Posts: 44
Joined: 02 February 2024, 08:56

Re: Separate persistence layer

Post 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.
imralav
Posts: 44
Joined: 02 February 2024, 08:56

Re: Separate persistence layer

Post 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.
User avatar
Tisaac
Posts: 2743
Joined: 26 August 2014, 21:28

Re: Separate persistence layer

Post 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
imralav
Posts: 44
Joined: 02 February 2024, 08:56

Re: Separate persistence layer

Post 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.
Post Reply

Return to “Developers”