comet icon indicating copy to clipboard operation
comet copied to clipboard

Database and Middleware example

Open codeezy opened this issue 4 years ago • 4 comments

Thanks for your framework. I try to use this, but i have a couple of questions.

  1. Can you add some example for Slim Middleware integration?
  • JWT
  • Rate Limit
  1. Explain an example the correct way to mysql connect with illuminate/database

codeezy avatar Jul 13 '20 08:07 codeezy

I'll show examples of using Slim middleware and DB connection with Laravel little bit later on docs.

You have to add to your composer.json:

composer require illuminate/database

And use Eloquent somewhere on the app like this:

...
use Illuminate\Database\Capsule\Manager as ORM;
...
$orm = new ORM;
$orm->addConnection([
    'driver'    => getenv('DB_TYPE'),
    'host'      => getenv('DB_HOST'),
    'port'      => getenv('DB_PORT'),
    'database'  => getenv('DB_NAME'),
    'username'  => getenv('DB_USER'),
    'password'  => getenv('DB_PASSWORD'),
    'options'   => [ \PDO::ATTR_TIMEOUT => 5 ],
]);
$orm->setAsGlobal();
...
$rows = ORM::select("SELECT * FROM table");
...

gotzmann avatar Jul 13 '20 22:07 gotzmann

Thank you, i will wait for your examples. I should say that JWT & Rate Limit need to be included in base package, because these are main middleware for REST. You have tested the Comet with Eloquent, how many rps we can expect?

codeezy avatar Jul 13 '20 23:07 codeezy

Eloquent performance is only at 50% of the equivalent PDO queries with prepared statements. Not good but no so bad either. I suppose Eloquent with entity models will be even slower. I'm struggling to find performant and popular ORM framework in PHP so stick with Eloquent now.

gotzmann avatar Jul 14 '20 08:07 gotzmann

Hi, I recommend the Idiorm, I have been using it for a few years, very simple and easy to use, but without the extra resources of Eloquent.

FelipoAntonoff avatar Mar 21 '21 20:03 FelipoAntonoff