Database
Optional plugin to track object ownership, folders, lifecycle, and listings in your database.
@dimah-s3/db is an optional
plugin for dimahS3. It keeps object ownership, upload
state, folders, and deletion history aligned with S3 without custom SQL on
every endpoint.
dimah-s3 works without a database. Add this plugin when you need ownership checks, usage totals and quotas, file listings with folders, or server-side tracking of each upload.
What the plugin does
- Tracks objects: writes a row when an upload starts, marks it active on confirm, and updates it on delete.
- Enforces ownership: each file belongs to a scope you define (for
example
user:123), and upload tickets are bound to it. Download requires a confirmed (active) object owned by that scope, and delete rejects another scope. This is per-caller tenancy, not the routekeyPrefixcheck: prefix isolation always runs in@dimah-s3/server. - Lists files: by scope on the server, and by folder, search, and sort in the browser.
- Adds folders: logical folders, renames, moves, and typed attributes per object. Folders never change the S3 key.
- Caps usage: checks a quota at upload and again with the verified size at confirm.
Authentication, quota values, and business rules stay application-owned. The plugin manages object metadata and scope isolation, and compares usage with the limits your application supplies.
Lifecycle
Each object moves through these statuses:
| Status | Meaning |
|---|---|
pending | Upload started, not confirmed |
active | Confirmed in S3, with the verified size stored |
deleted | Removed from S3, row kept (soft delete) |
purging | Expired before confirm, and being cleaned up by purge |
Typical flow: pending → active → deleted. A pending row expires with its
upload ticket, and purge cleans up rows that never reached
active.
Next steps
Database Setup
Install, create the tables, and register the plugin.
Database Lifecycle Hooks
Guards and hooks the plugin attaches to each route.
API
List, move, and annotate objects, manage folders, set quotas.
Purge Stale Uploads
Clean up uploads that never confirmed.
Upgrade the Schema
Move a 1.x database to schema 2.0.0.
Full example
Next.js + Drizzle file manager with folders and a quota.