Best Practices for Logging User Meta Data

In my panel, users have the option of checking in with their date and location. This is a separate function outside of the normal login.

How would you log the data? A lot of information can accumulate over time. I would prefer not to add it to the user, but to have a separate collection with all the data. A data set would look something like this:

fields:
  user:     
    label: User
    type: user
  timestamp: 
    label: Check-in
    type: date
  location: 
    label: Location
    type: text

I am afraid that a collection based on pages could slow down the system, especially if there are a lot of entries.

What would be a good approach?

Store in a sqlite db? If you need to view the data in the Panel, make it available via a custom area

I just looked at the documentation and there doesn’t seem to be a plugin extension for db. So this is not possible:

Kirby::plugin('flw/logs', [
    'db' => [
        'type'     => 'sqlite',
        'database' => function($kirby) {
            return  $kirby->root('site') . 'db/db_log';
        }
    ]
]);

What would be common practice to open the database in the plugin so that all functions can be accessed from it?

Otherwise I would write a class for it.

You can access the database directly without adding an extension

I need the same database connection in several places in the plugin. Is it then unnecessary that I have created such a DatabaseManager? Could I also define the connection once in the plugin and reuse it?


class DatabaseManager
{
    public static function connect()
    {
        $databasePath = kirby()->root('site') . '/db/db_main';

        return new Database([
            'type' => 'sqlite',
            'database' => $databasePath
        ]);
    }

    public static function query($sql, $bindings = [])
    {
        try {
            $db = self::connect();
            return $db->query($sql, $bindings);
        } catch (Exception $e) {
            return [
                "status" => "error",
                "message" => "Database error: " . $e->getMessage()
            ];
        }
    }
}

No, then that’s fine.