fire_duck_ext

Google Cloud Firestore direkt aus DuckDB mit SQL abfragen

Maintainer: BorisBesky

Installation und Laden

INSTALL fire_duck_ext FROM community;
LOAD fire_duck_ext;

Beispiel

LOAD fire_duck_ext;
-- Authenticate with a service account key file (see the README for API-key
-- and Firebase-user auth, including browser-safe authentication)
CREATE SECRET my_firestore (
TYPE firestore,
PROJECT_ID 'my-gcp-project',
SERVICE_ACCOUNT_JSON '/path/to/service-account.json'
);
-- Read documents
SELECT * FROM firestore_scan('users');
-- Filter with SQL
SELECT __document_id, name, email
FROM firestore_scan('users')
WHERE status = 'active';
-- Update a document
CALL firestore_update('users', 'user123', 'status', 'verified');
-- Insert documents from a subquery
CALL firestore_insert('users', (SELECT name, age FROM read_csv('new_users.csv')));

Über fire_duck_ext

fire_duck_ext ermöglicht die Arbeit mit Google Cloud Firestore direkt aus DuckDB mit SQL. Collections mit firestore_scan() scannen, einschließlich Collection-Group- Abfragen (firestore_scan(‘~collection’)) und der Ermittlung von Subcollection-IDs (firestore_scan(‘collection/doc_id’)). Schreiben mit firestore_insert(), firestore_update(), firestore_delete(), deren Batch-Gegenstücken (firestore_update_batch(), firestore_delete_batch()) sowie den Array-Transformations- Funktionen firestore_array_union(), firestore_array_remove() und firestore_array_append(). WHERE-Filter und SQL ORDER BY / LIMIT werden wo möglich an Firestore weitergereicht, um die übertragene Datenmenge zu reduzieren.

Die schemalosen Dokumente von Firestore werden automatisch auf typisierte DuckDB-Spalten abgebildet, mit konfigurierbarer Behandlung verschachtelter Maps (map_encoding) und Feldern, die nur in manchen Dokumenten vorkommen (schema_sample_size, unmapped_column, columns).

Secrets erfordern PROJECT_ID und eines von: einen Dateipfad zum Service-Account-Schlüssel (SERVICE_ACCOUNT_JSON, Adminzugriff, umgeht Security Rules über IAM, nur nativ) — betten Sie diesen Schlüssel niemals in Anwendungscode oder einen Browser- Kontext ein; einen API_KEY (nicht authentifiziert, request.auth ist null); oder Firebase- Auth-Benutzeranmeldedaten (EMAIL/PASSWORD, ANONYMOUS oder ein zuvor erhaltenes ID_TOKEN) — authentifiziert, respektiert Security Rules und funktioniert im WebAssembly-/Browser-Build. GOOGLE_APPLICATION_CREDENTIALS wird beim Start ebenfalls gelesen, falls gesetzt.

Die Erweiterung baut und läuft auch unter DuckDB-WASM mit API-Key- oder Firebase-Benutzerauthentifizierung (Service-Account-Auth benötigt OpenSSL und ist nur nativ).

Das vollständige Parameterverzeichnis, die Typabbildung, Pushdown-Semantik und Plattformhinweise finden Sie im Projekt (https://github.com/BorisBesky/fire_duck_ext).

Hinzugefügte Funktionen

function_name function_type description comment examples
firestore_scan table Read all documents from a Firestore collection or collection group. NULL [SELECT * FROM firestore_scan(‘users’);]
firestore_insert table Insert documents into a Firestore collection from a subquery. NULL [CALL firestore_insert(‘users’, (SELECT name, age FROM read_csv(‘new_users.csv’)));]
firestore_update table Update fields on a single Firestore document. NULL [CALL firestore_update(‘users’, ‘user123’, ‘status’, ‘verified’);]
firestore_delete table Delete a single Firestore document. NULL [CALL firestore_delete(‘users’, ‘user123’);]
firestore_update_batch table Batch update multiple Firestore documents by ID list. NULL [CALL firestore_update_batch(‘users’, [‘id1’, ‘id2’], ‘status’, ‘reviewed’);]
firestore_delete_batch table Batch delete multiple Firestore documents by ID list. NULL [CALL firestore_delete_batch(‘users’, [‘id1’, ‘id2’]);]
firestore_array_union table Add elements to an array field without duplicates. NULL [CALL firestore_array_union(‘users’, ‘user123’, ‘tags’, [‘vip’, ‘active’]);]
firestore_array_remove table Remove elements from an array field. NULL [CALL firestore_array_remove(‘users’, ‘user123’, ‘tags’, [‘inactive’]);]
firestore_array_append table Append elements to an array field (allows duplicates). NULL [CALL firestore_array_append(‘users’, ‘user123’, ‘log’, [‘event1’]);]
firestore_clear_cache table Clear the cached schema for all or a specific collection. NULL [CALL firestore_clear_cache();]
firestore_connect table Set the session-scoped Firestore database for subsequent queries. NULL [CALL firestore_connect(‘analytics-db’);]
firestore_disconnect table Clear the session-scoped Firestore database override. NULL [CALL firestore_disconnect();]

Überladene Funktionen

Diese Erweiterung fügt keine Funktionsüberladungen hinzu.

Hinzugefügte Typen

Diese Erweiterung fügt keine Typen hinzu.

Hinzugefügte Einstellungen

name description input_type scope aliases
firestore_schema_cache_ttl Schema cache TTL in seconds (0 to disable caching) BIGINT GLOBAL []
firestore_schema_sample_size Documents sampled to infer a collection’s schema (-1 samples every document) BIGINT GLOBAL []