StorageAnalyticsClient
import { StorageAnalyticsClient } from "https://esm.sh/@supabase/storage-js@2.89.0/dist/index.d.mts";Client class for managing Analytics Buckets using Iceberg tables Provides methods for creating, listing, and deleting analytics buckets
§Constructors
- The base URL for the storage API
- HTTP headers to include in requests
- Optional custom fetch implementation
const client = new StorageAnalyticsClient(url, headers)
§Properties
§Methods
A unique name for the bucket you are creating
Promise with response containing newly created analytics bucket or error
Create analytics bucket
const { data, error } = await supabase
.storage
.analytics
.createBucket('analytics-data')
Response:
{
"data": {
"name": "analytics-data",
"type": "ANALYTICS",
"format": "iceberg",
"created_at": "2024-05-22T22:26:05.100Z",
"updated_at": "2024-05-22T22:26:05.100Z"
},
"error": null
}
The unique identifier of the bucket you would like to delete
Promise with response containing success message or error
Delete analytics bucket
const { data, error } = await supabase
.storage
.analytics
.deleteBucket('analytics-data')
Response:
{
"data": {
"message": "Successfully deleted"
},
"error": null
}
- The name of the analytics bucket (warehouse) to connect to
The wrapped Iceberg catalog client
Get catalog and create table
// First, create an analytics bucket
const { data: bucket, error: bucketError } = await supabase
.storage
.analytics
.createBucket('analytics-data')
// Get the Iceberg catalog for that bucket
const catalog = supabase.storage.analytics.from('analytics-data')
// Create a namespace
const { error: nsError } = await catalog.createNamespace({ namespace: ['default'] })
// Create a table with schema
const { data: tableMetadata, error: tableError } = await catalog.createTable(
{ namespace: ['default'] },
{
name: 'events',
schema: {
type: 'struct',
fields: [
{ id: 1, name: 'id', type: 'long', required: true },
{ id: 2, name: 'timestamp', type: 'timestamp', required: true },
{ id: 3, name: 'user_id', type: 'string', required: false }
],
'schema-id': 0,
'identifier-field-ids': [1]
},
'partition-spec': {
'spec-id': 0,
fields: []
},
'write-order': {
'order-id': 0,
fields: []
},
properties: {
'write.format.default': 'parquet'
}
}
)
List tables in namespace
const catalog = supabase.storage.analytics.from('analytics-data')
// List all tables in the default namespace
const { data: tables, error: listError } = await catalog.listTables({ namespace: ['default'] })
if (listError) {
if (listError.isNotFound()) {
console.log('Namespace not found')
}
return
}
console.log(tables) // [{ namespace: ['default'], name: 'events' }]
Working with namespaces
const catalog = supabase.storage.analytics.from('analytics-data')
// List all namespaces
const { data: namespaces } = await catalog.listNamespaces()
// Create namespace with properties
await catalog.createNamespace(
{ namespace: ['production'] },
{ properties: { owner: 'data-team', env: 'prod' } }
)
Cleanup operations
const catalog = supabase.storage.analytics.from('analytics-data')
// Drop table with purge option (removes all data)
const { error: dropError } = await catalog.dropTable(
{ namespace: ['default'], name: 'events' },
{ purge: true }
)
if (dropError?.isNotFound()) {
console.log('Table does not exist')
}
// Drop namespace (must be empty)
await catalog.dropNamespace({ namespace: ['default'] })
Query parameters for listing buckets
Maximum number of buckets to return
Number of buckets to skip
Column to sort by ('name', 'created_at', 'updated_at')
Sort order ('asc' or 'desc')
Search term to filter bucket names
Promise with response containing array of analytics buckets or error
List analytics buckets
const { data, error } = await supabase
.storage
.analytics
.listBuckets({
limit: 10,
offset: 0,
sortColumn: 'created_at',
sortOrder: 'desc'
})
Response:
{
"data": [
{
"name": "analytics-data",
"type": "ANALYTICS",
"format": "iceberg",
"created_at": "2024-05-22T22:26:05.100Z",
"updated_at": "2024-05-22T22:26:05.100Z"
}
],
"error": null
}