This is a PHP client for the Deta API.
Explore the Client Deta Space via https://deta.space/discovery/@tuefekci/phpsandbox
You can install the package via composer:
composer require tuefekci/deta
To use the Deta client, first create an instance of the Deta
class, passing in your project ID and API key:
use tuefekci\deta\Deta;
$deta = new Deta('your_project_id', 'your_api_key');
If you have set ENV Variables or are in a Deta Micro you can leave the keys out.
use tuefekci\deta\Deta;
$deta = new Deta();
Then, you can use the base
method to get a reference to a base in your project:
$my_base = $deta->base('my_base');
You can then use the methods on the base to interact with the items stored in the base:
// Insert an item
$my_base->insert(['name' => 'Alice', 'age' => 30]);
// Get an item by key
$item = $my_base->get('abc123');
// Update an item
$my_base->update('abc123', ['name' => 'Bob']);
// Delete an item
$my_base->delete('abc123');
// Query items
$items = $my_base->query(['age' => ['lt' => 40]]);
Similarly, you can use the drive
method to get a reference to a drive in your project:
$my_drive = $deta->drive('my_drive');
And then use the methods on the drive to interact with the files stored in the drive:
// Upload a file
$my_drive->put('file.txt', 'Hello, world!');
// Download a file
$content = $my_drive->get('file.txt');
// List files
$files = $my_drive->list();
This repository contains Deta-PHP
, which is a PHP SDK for interacting with the Deta API. The SDK contains the following files and classes:
This file contains the Deta
class, which is used to instantiate a Deta client. The Deta
class constructor takes the following parameters:
project_id
: the Deta project IDapi_key
: the Deta project API keyoptions
: an optional array of options for the Guzzle HTTP client
The Deta
class provides the following methods:
base($base_name)
: creates and returns a newBase
instancedrive($drive_name)
: creates and returns a newDrive
instance
This file contains the Base
class, which provides methods for interacting with Deta Base. The Base
class constructor takes a single parameter, which is an instance of the Guzzle HTTP client.
The Base
class provides the following methods:
put($items)
: adds or updates items in the baseget($key)
: retrieves an item from the base by keydelete($key)
: deletes an item from the base by keyinsert($item)
: adds a new item to the baseupdate($key, $set = null, $increment = null, $append = null, $delete = null)
: updates an item in the base by keyquery($query = null, $limit = null, $last = null)
: queries the base
This file contains the Drive
class, which provides methods for interacting with Deta Drive. The Drive
class constructor takes a single parameter, which is an instance of the Guzzle HTTP client.
The Drive
class provides the following methods:
put($name, $content, $content_type = null)
: uploads a new file to Deta DriveinitializeChunkedUpload($name)
: initiates a chunked upload to Deta DriveuploadChunkedPart($upload_id, $name, $part, $content)
: uploads a part of a chunked upload to Deta DriveendChunkedUpload($upload_id, $name)
: ends a chunked upload to Deta DriveabortChunkedUpload($upload_id, $name)
: aborts a chunked upload to Deta Driveget($name)
: retrieves a file from Deta Drivelist($limit = null, $prefix = null, $last = null)
: lists files in Deta Drivedelete($name)
: deletes a file from Deta Drive by name
All classes are defined in the tuefekci\deta
namespace. To use the SDK in your PHP code, include the following statement:
use tuefekci\deta\Deta;
use tuefekci\deta\Base;
use tuefekci\deta\Drive;
The MIT License (MIT). Please see License File for more information.