mevdschee / php-crud-api

Single file PHP script that adds a REST API to a SQL database
MIT License
3.6k stars 1.01k forks source link

Is there a a community space for this project? #804

Open ivan006 opened 3 years ago

ivan006 commented 3 years ago

This project from the onset seems very apt/intelligent. Are there any community space for users of this system to communicate and compare notes etc? I'd like to learn more and see the full potential.

mevdschee commented 3 years ago

This project from the onset seems very apt/intelligent.

Thank you for your kind words.

Are there any community space for users of this system to communicate and compare notes etc?

Not that I'm aware of (other than Github issues).

Kind regards, Maurits

ivan006 commented 3 years ago

does this integrate with any other libraries like datatables?

mevdschee commented 3 years ago

does this integrate with any other libraries like datatables?

Sure, why not?

ivan006 commented 3 years ago

scrutiny warning

yeah but im wondering has anyone demonstrated how to do this so others can do it more easily? who uses this library and how have they used it? how has this library been useful to others? the concept sounds sensible but if its not implemented then me implementing it will take more effort. how can i get the most bang for my "buck" with this library?

mevdschee commented 3 years ago

Lot's of questions that I can't help you with (I don't know the answers). You may try it out and help others by publishing your findings.

If you need a user interface, then you may try: https://github.com/mevdschee/php-crud-ui

It is my take on a usable (and high performance) user interface for the API.

Kind regards, Maurits

ivan006 commented 3 years ago

Cool thanks. Do you mind demoing it in a youtube video? (screencastify chrome plugin can help record in case u dont know of any recording tools)

mevdschee commented 3 years ago

Why don't you try to run it with your own dataset? I'm here to help you out when you run into problems. Also, feel free to create a YouTube video about it.

ivan006 commented 3 years ago

How about just a screenshot? Its a lot of hours for me to set up libraries

ivan006 commented 3 years ago

Im very interested in crud generators and the like i have myself made a more dynamic crud generator that works for any table, this means you dont have to generate a new crud functionality for each table. My engine also allows for seeing records that are related to a record. E.g. here is record 2 in the commodity type table and its related items.

The key here of course is in its dynamic-ness and it uses ajax pagination so of course i have my own dynamic api in addition to the ui. But im just wanting to compare notes with others to see if i can improve my setup. Another key thing in my app is the relationship visibility as mentioned.

image

mevdschee commented 3 years ago

Screen Shot 2021-09-08 at 01 58 27


Screen Shot 2021-09-08 at 01 58 40


Screen Shot 2021-09-08 at 01 58 46


Screen Shot 2021-09-08 at 01 58 54

mevdschee commented 3 years ago

Im very interested in crud generators and the like i have myself made a more dynamic crud generator that works for any table

Nice, did you publish it? Can I try it out?

ivan006 commented 3 years ago

Yes but do u mean as an installable library? If so no its only available as a full app https://github.com/ivan006/Bg---table-page-3---free-php-spreadsheet-database-hybrid I will make a youtube video on how to set it up when i have the time thanks for ur interest. And thanks for the screenshots.

So in your app i see you can "view" a record so when u are viewing a record can u see related records? boths parents and children?

mevdschee commented 3 years ago

when u are viewing a record can u see related records? boths parents and children?

You can only see a link to the filtered list (of children).


Screen Shot 2021-09-08 at 15 30 21


Screen Shot 2021-09-08 at 15 29 34

ivan006 commented 3 years ago

Wow and that "post='blog started'" thats cool. I understand "post" refers to the table but what does "blog started" refer to is searching all columns or a specific column if its a specific column then how do u flag which column is priority?

mevdschee commented 3 years ago

'Post' is short for 'post_id' (a fk filter on the comments table) and 'blog started' is the default representation of a record in the related table (the value in the 'name' field)

ivan006 commented 3 years ago

Ok cool, and then this unfortunately contains the developer to have to create a column with the name "name". Yeah my system also has those kinds of constraints for instance the primary key has to called "id" which makes the system a bit rigid, oh well u cant win them all.

mevdschee commented 3 years ago

this unfortunately contains the developer to have to create a column with the name "name".

It returns the first text column, in this case 'name', see:

private function getDisplayColumn(string $table, string $action)
{
    $properties = $this->getProperties($table, $action);

    foreach ($properties as $field => $property) {
        if ($property['type'] == 'string') {
            return $field;
        }
    }
    return false;
}

from: https://github.com/mevdschee/php-crud-ui/blob/main/src/Tqdev/PhpCrudUi/Column/SpecificationService.php#L177

I hope this helps you in any way. Kind regards, Maurits

mevdschee commented 3 years ago

Yeah my system also has those kinds of constraints for instance the primary key has to called "id" which makes the system a bit rigid

I don't have that constraint. I request the primary key from the information schema (it may not be composite), see:

private function getTablePrimaryKeysSQL(): string
{
    switch ($this->driver) {
        case 'mysql':
            return 'SELECT "COLUMN_NAME" FROM "INFORMATION_SCHEMA"."KEY_COLUMN_USAGE" WHERE "CONSTRAINT_NAME" = \'PRIMARY\' AND "TABLE_NAME" = ? AND "TABLE_SCHEMA" = ?';
        case 'pgsql':
            return 'SELECT a.attname AS "COLUMN_NAME" FROM pg_attribute a JOIN pg_constraint c ON (c.conrelid, c.conkey[1]) = (a.attrelid, a.attnum) JOIN pg_class pgc ON pgc.oid = a.attrelid WHERE pgc.relname = ? AND \'\' <> ? AND c.contype = \'p\'';
        case 'sqlsrv':
            return 'SELECT c.NAME as "COLUMN_NAME" FROM sys.key_constraints kc inner join sys.objects t on t.object_id = kc.parent_object_id INNER JOIN sys.index_columns ic ON kc.parent_object_id = ic.object_id and kc.unique_index_id = ic.index_id INNER JOIN sys.columns c ON ic.object_id = c.object_id AND ic.column_id = c.column_id WHERE kc.type = \'PK\' and t.object_id = OBJECT_ID(?) and \'\' <> ?';
        case 'sqlite':
            return 'SELECT "name" as "COLUMN_NAME" FROM pragma_table_info(?) WHERE "pk"=1 AND \'\' <> ?';
    }
}

from: https://github.com/mevdschee/php-crud-api/blob/main/src/Tqdev/PhpCrudApi/Database/GenericReflection.php#L66

I hope this helps you in any way. Kind regards, Maurits

mevdschee commented 3 years ago

I read the database structure and make a database independent model of it first. Only to generate the API or UI from that model, not directly from the reflection results. Instead of using reflection on every request I have a cache engine that can hold the reflected information, avoiding heavy load on the database server due to many reflection queries.

mevdschee commented 3 years ago

my system also has those kinds of constraints

My constraints are:

from: https://github.com/mevdschee/php-crud-api#limitations

ivan006 commented 3 years ago

Im very interested in crud generators and the like i have myself made a more dynamic crud generator that works for any table

Nice, did you publish it? Can I try it out?

As promised here it (the tutorial) finally is https://www.youtube.com/watch?v=TOyiUzKToA0&list=PLDjAbnn_RxMIwOTO-3ciB1E1UmB8MEv4u

mevdschee commented 3 years ago

Wow.. what a work.. I mean.. the video.. the code.. everything! Congrats and thank you for sharing.

ivan006 commented 3 years ago

Wow.. what a work.. I mean.. the video.. the code.. everything! Congrats and thank you for sharing.

So kind thank you

ivan006 commented 2 years ago

Let me know when/if u get round to installing my app or just watching the videos