IO

backend.IO (Class)
Implements: spec.IO

Clay backend implementation for persistent key-value storage.

This class provides cross-platform persistent storage with different implementations based on the target platform:

  • Desktop (sys + SQLite): Uses SQLite database for efficient storage
  • Desktop (sys without SQLite): Falls back to individual files
  • Web: Uses browser localStorage API

Key features:

  • All data is encoded with MD5 hashing for integrity verification
  • Keys are hashed to avoid filesystem issues with special characters
  • Supports importing initial SQLite database from assets
  • Thread-safe on platforms that support it

The SQLite implementation allows importing a pre-populated database from assets on first run, useful for shipping default data.

See: spec.IO The interface this class implements, ceramic.PersistentData For the high-level storage API

Instance Members

clay
saveString(key: String, str: String): Bool

File-based implementation of saveString for sys targets without SQLite. Stores each key-value pair as a separate file in the storage directory.

Name Type
key String
str String
Returns
Bool

clay
appendString(key: String, str: String): Bool
Name Type
key String
str String
Returns
Bool

clay
readString(key: String): String
Name Type
key String
Returns
String

clay
new(): Void

Private Members

clay
initKeyValueIfNeeded(): Void

Initializes the key-value storage backend if needed. Called by the main backend during initialization.