https://github.com/duckdb/duckdb
- Download CLI (either)
- https://duckdb.org/docs/installation/
- https://github.com/duckdb/duckdb/releases/latest
- run
php artisan laravel-duckdb:download-cli
(Experimental) - You can also pass argument
--ver
for specific version likephp artisan laravel-duckdb:download-cli --ver=0.7.1
You can install the package via composer:
composer require harish81/laravel-duckdb
- Connect
'connections' => [
'my_duckdb' => [
'driver' => 'duckdb',
'cli_path' => env('DUCKDB_CLI_PATH', base_path('vendor/bin/duckdb')),
//'dbfile' => env('DUCKDB_DB_FILE', '/tmp/duck_main.db'),
],
...
- Examples
# Using DB facade
DB::connection('my_duckdb')
->table(base_path('genderdata.csv'))
->where('Gender', '=', 'M')
->limit(10)
->get();
# Using Raw queries
DB::connection('my_duckdb')
->select("select * from '".base_path('genderdata.csv')."' limit 5")
# Using Eloquent Model
class GenderDataModel extends \Harish\LaravelDuckdb\LaravelDuckdbModel
{
protected $connection = 'my_duckdb';
public function __construct()
{
$this->table = base_path('genderdata.csv');
}
}
...
GenderDataModel::where('Gender','M')->first()
You can install duckdb extensions too.
- in
database.php
'connections' => [
'my_duckdb' => [
'driver' => 'duckdb',
'cli_path' => env('DUCKDB_CLI_PATH', base_path('vendor/bin/duckdb')),
'cli_timeout' => 0, //0 to disable timeout, default to 1 Minute (60s)
'dbfile' => env('DUCKDB_DB_FILE', storage_path('app/duckdb/duck_main.db')),
'pre_queries' => [
"SET s3_region='".env('AWS_DEFAULT_REGION')."'",
"SET s3_access_key_id='".env('AWS_ACCESS_KEY_ID')."'",
"SET s3_secret_access_key='".env('AWS_SECRET_ACCESS_KEY')."'",
],
'extensions' => ['httpfs'],
],
...
- Query data
DB::connection('my_duckdb')
->select("SELECT * FROM read_csv_auto('s3://my-bucket/test-datasets/example1/us-gender-data-2022.csv') LIMIT 10")
return new class extends Migration {
protected $connection = 'my_duckdb';
public function up(): void
{
DB::connection('my_duckdb')->statement('CREATE SEQUENCE people_sequence');
Schema::create('people', function (Blueprint $table) {
$table->id()->default(new \Illuminate\Database\Query\Expression("nextval('people_sequence')"));
$table->string('name');
$table->integer('age');
$table->integer('rank');
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('people');
DB::connection('my_duckdb')->statement('DROP SEQUENCE people_sequence');
}
};
- in
database.php
'connections' => [
'my_duckdb' => [
'driver' => 'duckdb',
'cli_path' => env('DUCKDB_CLI_PATH', base_path('vendor/bin/duckdb')),
'cli_timeout' => 0,
'dbfile' => env('DUCKDB_DB_FILE', storage_path('app/duckdb/duck_main.db')),
'schema' => 'main',
'read_only' => true,
'pre_queries' => [
"SET s3_region='".env('AWS_DEFAULT_REGION')."'",
"SET s3_access_key_id='".env('AWS_ACCESS_KEY_ID')."'",
"SET s3_secret_access_key='".env('AWS_SECRET_ACCESS_KEY')."'",
],
'extensions' => ['httpfs', 'postgres_scanner'],
],
...
- Generate test data
# Syntax: ./data-generator.sh <lines> <file-to-save.csv>
./data-generator.sh 100 _test-data/test.csv
./data-generator.sh 90000000 _test-data/test_big_file.csv
- Run Test case
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.