Repository navigation
10. Data import and export
The data import feature relies on the Jaxon upload feature, which is configured in the Jaxon library config file.
The uploaded file id is sql_files, and in the above examples, it is stored in a local dir, set in the storage->stores entry with the uploads id.
'storage' => [
'stores' => [
'uploads' => [
'adapter' => 'local',
'dir' => storage_path('/uploads'),
],
'exports' => [
'adapter' => 'local',
'dir' => storage_path('/exports'),
],
],
],
'upload' => [
'enabled' => true,
'files' => [
'sql_files' => [
'storage' => 'uploads',
],
],
], storage:
stores:
uploads:
adapter: local
dir: '%kernel.project_dir%/var/uploads'
exports:
adapter: local
dir: '%kernel.project_dir%/var/exports'
uploads:
enabled: true
files:
sql_files:
storage: uploadsAfter the uploaded file is received, Jaxon DbAdmin will parse its content, and execute the SQL queries one after another.
The data export feature also requires a storage entry to be defined in the Jaxon library config file.
Additionally, the export entry in the app.php config file defines a closure which return an instance of the FileSystemInterface interface.
This interface provides two functions to write the export content in a file in the storage, and read this file for display in the browser.
namespace Lagdo\DbAdmin\Support\Service\Export;
/**
* Read and write database export files.
*/
interface FileSystemInterface
{
/**
* @param string $content
* @param string $filename
*
* @return string
*/
public function write(string $content, string $filename): string;
/**
* @param string $filename
*
* @return string
*/
public function read(string $filename): string;
}In the ready-to-use applications, the abstract Lagdo\DbAdmin\Support\Service\Export\AbstractFileSystem class implements the FileSystemInterface interface, and defines another set of abstract methods to be defined in the provided class.
For example, this is the entry for the Laravel application.
'export' => fn() => new class extends Service\Export\AbstractFileSystem {
protected function storage(): string
{
return 'exports';
}
protected function path(string $filename): string
{
// Use the slugified username to customize the path.
$userId = auth()->userId();
$userDir = $userId === '' ? 'users' : 'users/' . Str::slug($userId);
return "$userDir/$filename";
}
protected function url(string $filename): string
{
return route('export_file', ['filename' => $filename]);
}
},