Skip to content

Managing Data

How to work with data?

lethal.landing is database-less! No need to deal with complicated SQL queries, thanks to .json!

By default, all data is being cached, the cache will automatically be refreshed when data changes. Awesome, right?

If your add-on requires storing data, find out below on how it's done and if that is not enough to get you started read more on Filebases Docs.

Important! Read me!

Make sure to always set the correct file paths, if you fail to do, so you could possibly overwrite or not even find existing data! lethal.landing and official add-ons save their data in /lethal.landing/data/.

Changing Data:

<?php
    use Filebase\Database;

    // Define an instance of the file database
    $cookies = new Database([
        // Set the storage location relative to the current files path
        'dir' => __DIR__ . '/../../../data/c_example_addon/cookies'
    ]);

    // Check if a record exists and do something if it does
    if ($cookies->has('chocolate_cookie'))
    {
        // Search for 'chocolate_cookie' if 'chocolate_cookie' doesn't exist,
        // it will return new empty document otherwise returns the document
        $cookie = $cookies->get('chocolate_cookie');

        // Change properties of 'chocolate_cookie'
        $cookie->dark_chocolate = '100grams';
        $cookie->baking_temperature = 180;
        $cookie->is_tasty = true;

        // Save changes
        $cookie->save();
    }

Where Clause:

<?php
    use Filebase\Database;

    // Define an instance of the file database
    $cookies = new Database([
        // Set the storage location relative to the current files path
        'dir' => __DIR__ . '/../../../data/c_example_addon/cookies'
    ]);

    // Search for data where 'baking_temperature = 180'
    $cookie = $cookies->where('baking_temperature', '=', '180')->resultDocuments();

    // Multiple Where clauses are possible and orWhere() as well check the official docs!

Delete Data:

<?php
    use Filebase\Database;

    // Define an instance of the file database
    $cookies = new Database([
        // Set the storage location relative to the current files path
        'dir' => __DIR__ . '/../../../data/c_example_addon/cookies'
    ]);

    // Get the Data
    $cookie = $cookies->get('chocolate_cookie');

    // Then delete it...
    $cookie->delete();

Miscellaneous:

<?php
    use Filebase\Database;

    // Define an instance of the file database
    $cookies = new Database([
        // Set the storage location relative to the current files path
        'dir' => __DIR__ . '/../../../data/c_example_addon/cookies',
        'backupLocation' => __DIR__ . '/../../../backup',
    ]);

    // Get total count
    $total_count = $cookies->count();

    // Get all cookies
    $all_cookies = $cookies->findAll();

    // Create a backup
    $cookies->backup()->create();