1. Go to this page and download the library: Download survos/grist-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
survos / grist-php example snippets
use Survos\Grist\Adapter\GristAdapterFactory;
use Survos\RecordStore\Model\{ConnectionConfiguration, Record, RecordQuery, TableReference, UpsertRequest};
use Symfony\Component\HttpClient\HttpClient;
$factory = new GristAdapterFactory(HttpClient::create());
$adapter = $factory->create(new ConnectionConfiguration(
name: 'pgsc',
driver: 'grist',
options: [
'base_uri' => 'https://grist.example.org/api/',
'token' => $_ENV['GRIST_API_KEY'],
// 'timeout' => 30.0,
],
));
$artists = new TableReference(
application: 'pgsc',
applicationId: $documentId, // the Grist doc id
connection: 'pgsc',
name: 'artists', // your logical name
id: 'Artists', // the table id in Grist
);
$page = $adapter->query($artists, new RecordQuery(limit: 20));
foreach ($page->records as $record) {
echo $record->id, ': ', $record->fields['Name'] ?? '', PHP_EOL;
}
$adapter->upsert($artists, new UpsertRequest(
records: [new Record(fields: ['Bio' => 'Updated bio'], id: 42)],
));
use Survos\Grist\Adapter\GristAdapterFactory;
$client = (new GristAdapterFactory(HttpClient::create()))->client($connection);
$client->tables($documentId);
$client->columns($documentId, 'Artists');
$client->queryRecords(/* … */);
$client->addRecords($documentId, 'Artists', $records);
$client->upsertRecords($documentId, 'Artists', $records);
$client->request('GET', 'docs/'.$documentId.'/sql?q=…'); // anything not wrapped yet
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.