gabordemooij / redbean

ORM layer that creates models, config and database on the fly
https://www.redbeanphp.com
2.3k stars 280 forks source link

Switching to redbean?I #901

Closed KoljaL closed 1 year ago

KoljaL commented 2 years ago

I hope that my request is not wrong here.

It's about the redesign of my last project, a PHP API for a customer / appointment management. The structure is quite simple, there are employees, customers, projects and appointments, each as a separate table in a database.

Logically, each employee can have multiple customers, each customer multiple projects, each project multiple appointments. For that, i.e. the table appointments has three additional columns: staff_id, customer_id and project_id. There is no relationship between the tables at the database level.

So far the system works satisfactorily, but now there should be the function that employees can share customers, projects and appointments among themselves, so visible or editable for other employees.

After I solved this by adding three more tables (customer_sharing, etc) I realized that dealing with this becomes very complex at some point and I started looking for fundamentally different ways.

Thereby I came across redbeanPHP and have read a lot about it with pleasure. Everything I did not understand, because I did not know ORM before.

Before I now start with a restart of my API, I would like to know if redbean is really a relief for my requirement.

Lynesth commented 2 years ago

I would say that what you are describing could indeed be done with Redbean. But you mentioned something I think need more precision before I could give you an actual proper answer.

You say "dealing with this becomes very complex at some point and I started looking for fundamentally different ways".

How were you doing things? What part of what you are doing is becoming complex for you? Redbean only alleviate the "database" part of things for you but doesn't do any kind of magic. It won't suddently manage permissions between your employees and their customers/projects/appointments.

KoljaL commented 2 years ago

Hi @Lynesth and thank you for your detailed reply.
Please excuse my late response, I was on vacation :-)

You are of course right about Redbean not taking away the complexity of permissions from me. My hope is that with the experience from the first project and the features of Redbean, I can write the new version a little less cluttered.
You can find the repo of my first attempt here.

The biggest change will be that I will simply create a separate function or date for each endpoint and not try to distinguish many cases in one function with parameters.

In the old Redbead documentation, there is the Resty BeanCan Server, but it is no longer listed in the current doc. 
Does it still exist and is it useful for me to use it?

I have many more questions, but for now I will try some experiments with Redbean :-9

marios88 commented 2 years ago

@KoljaL In general redbean makes yours ( and ours ) life easier. But dont forget, using raw sql will be easier and way faster sometimes

Since you are starting a new project i strongly suggest using PHP 8.0+ with the excellent type hinting system, it just works with the IDE.

Ps: extend TypedModel and you can have stuff like setters/getters, add class traits

gabordemooij commented 2 years ago

Personally I use RedBeanPHP for all my PHP projects. I just use it in the most basic form though. Most advanced features have been added for (and by) the community. Personally I only use the basics (I do use the extended SQL syntax though), but I use it for every project. In your case I think the $bean->sharedList is probably interesting to use, maybe also the via()-function. To be honest I myself never use types in PHP, most of the time, I even rely on the implicit behavior of automatic type casting (because it saves time and key strokes). But types are trending these days, so I guess if that is your thing, just use it. The Bean Can server was more like a failed experiment, I realized that if you use that in the wrong way it might be easy to create security issues. Also, it is almost trivial to make something like it yourself and it would be much better suited to your needs. So there was no point in developing it further. You might want to take a look at Straight though (even for an API): https://gabordemooij.com/straight/. It has a very nice little request-mapper (that is also very fast). Happy to answer any other questions you might have.

KoljaL commented 2 years ago

Hi @marios88 thanks for the hint about type hinting, but on the one hand I can't program OOP and on the other hand my API is much too simple to extend my programming style.

In brief, my API function flow:

@gabordemooij okay, i will forget the BeanCanServer as well as the type hinting ;-) But although Straight looks a little too much for my purpose. In the next days, i will have a look at the sharedList and the via() function. I found them in the documentation and will try it by myself, maybe you could have an eye on it after i got a working example?

Thanks a lot, Kolja