Convert Figma logo to code with AI

pmwkaa logosophia

Modern transactional key-value/row storage library.

1,853
155
1,853
56

Top Related Projects

28,234

A library that provides an embeddable, persistent key-value store for fast storage.

FoundationDB - the open source, distributed, transactional key-value store

13,494

🥑 ArangoDB is a native multi-model database with flexible data models for documents, graphs, and key-values. Build high performance applications using a convenient SQL-like query language or JavaScript extensions.

4,766

RocksDB/LevelDB inspired key-value database in Go

Quick Overview

Sophia is a lightweight, embeddable, transactional key-value database written in C. It is designed to be fast, reliable, and easy to integrate into applications that require a persistent storage solution.

Pros

  • Lightweight and Embeddable: Sophia is a self-contained, single-file library that can be easily integrated into applications without the need for a separate server or external dependencies.
  • Transactional and Durable: Sophia provides ACID (Atomicity, Consistency, Isolation, Durability) guarantees, ensuring data integrity and reliability.
  • High Performance: Sophia is designed to be fast, with low latency and high throughput, making it suitable for applications that require efficient data storage and retrieval.
  • Cross-Platform: Sophia is written in portable C code and can be compiled and used on a variety of platforms, including Windows, Linux, and macOS.

Cons

  • Limited Query Capabilities: Sophia is primarily a key-value store and does not provide advanced querying capabilities like SQL databases or document-oriented databases.
  • Lack of Replication and Clustering: Sophia is a single-node database and does not currently support replication or clustering, which may limit its scalability for large-scale applications.
  • Limited Documentation: The project's documentation could be more comprehensive, which may make it more challenging for new users to get started with Sophia.
  • Relatively Niche: Sophia is a relatively niche database solution, and it may not have the same level of community support and ecosystem as more popular database technologies.

Code Examples

Here are a few code examples demonstrating the usage of Sophia:

  1. Initializing and Opening a Database:
#include <sophia.h>

int main() {
    sp_env *env = sp_env();
    sp_open(env);
    // Use the database
    sp_close(env);
    sp_destroy(env);
    return 0;
}
  1. Inserting and Retrieving Data:
#include <sophia.h>

int main() {
    sp_env *env = sp_env();
    sp_open(env);

    // Insert a key-value pair
    sp_key *key = sp_document(env);
    sp_setstring(key, "key", "hello", 5);
    sp_setstring(key, "value", "world", 5);
    sp_set(env, key);

    // Retrieve the value
    sp_key *get_key = sp_document(env);
    sp_setstring(get_key, "key", "hello", 5);
    sp_get(env, get_key);
    const char *value = sp_getstring(get_key, "value", NULL);
    printf("Value: %s\n", value);

    sp_destroy(key);
    sp_destroy(get_key);
    sp_close(env);
    sp_destroy(env);
    return 0;
}
  1. Performing a Transactional Operation:
#include <sophia.h>

int main() {
    sp_env *env = sp_env();
    sp_open(env);

    // Begin a transaction
    sp_tx *tx = sp_begin(env);

    // Insert a key-value pair
    sp_key *key = sp_document(env);
    sp_setstring(key, "key", "hello", 5);
    sp_setstring(key, "value", "world", 5);
    sp_set(tx, key);

    // Commit the transaction
    sp_commit(tx);

    sp_destroy(key);
    sp_close(env);
    sp_destroy(env);
    return 0;
}

Getting Started

To get started with Sophia, follow these steps:

  1. Download the latest version of Sophia from the GitHub repository.
  2. Extract the downloaded archive and navigate to the sophia directory.
  3. Compile the Sophia library by running the following commands:
    $ make
    $ sudo make install
    
  4. In your C project, include the

Competitor Comparisons

28,234

A library that provides an embeddable, persistent key-value store for fast storage.

Pros of RocksDB

  • Widely adopted and battle-tested in production environments
  • Extensive documentation and community support
  • Rich feature set, including column families and transactions

Cons of RocksDB

  • Higher memory usage and larger disk footprint
  • More complex API and configuration options
  • Slower write performance in some scenarios

Code Comparison

RocksDB:

rocksdb::DB* db;
rocksdb::Options options;
options.create_if_missing = true;
rocksdb::Status status = rocksdb::DB::Open(options, "/path/to/db", &db);

Sophia:

void *env = sp_env();
void *db = sp_open(env);
int rc = sp_set(db, "key", 3, "value", 5);

RocksDB offers a more feature-rich API with additional options and configurations, while Sophia provides a simpler, more straightforward interface. RocksDB's code is more verbose but allows for fine-tuned control over database behavior. Sophia's API is more compact and easier to use for basic operations, but may lack some advanced features found in RocksDB.

Both databases have their strengths and weaknesses, and the choice between them depends on specific project requirements, performance needs, and development preferences.

FoundationDB - the open source, distributed, transactional key-value store

Pros of FoundationDB

  • Highly scalable and distributed architecture, supporting multi-node clusters
  • Strong ACID guarantees with support for multi-key transactions
  • Backed by Apple, with a large and active community

Cons of FoundationDB

  • More complex setup and configuration compared to Sophia
  • Steeper learning curve due to its distributed nature
  • Potentially higher resource requirements for small-scale applications

Code Comparison

FoundationDB (Python):

@fdb.transactional
def add_user(tr, user_id, name):
    tr[f'users:{user_id}:name'] = name

fdb.open()
add_user(db, '123', 'John Doe')

Sophia (C):

void *db = sp_open("users.db");
sp_set(db, "users:123:name", "John Doe");
sp_close(db);

Summary

FoundationDB is a distributed database system offering strong consistency and scalability, ideal for large-scale applications. Sophia, on the other hand, is a simpler key-value store focused on embedded use and high performance. FoundationDB provides more advanced features but requires more setup, while Sophia offers ease of use and lower overhead for simpler use cases.

13,494

🥑 ArangoDB is a native multi-model database with flexible data models for documents, graphs, and key-values. Build high performance applications using a convenient SQL-like query language or JavaScript extensions.

Pros of ArangoDB

  • Multi-model database supporting key/value, document, and graph data
  • Highly scalable with clustering and sharding capabilities
  • Rich query language (AQL) for complex data operations

Cons of ArangoDB

  • Higher resource consumption due to its comprehensive feature set
  • Steeper learning curve for new users
  • More complex setup and configuration compared to simpler databases

Code Comparison

Sophia (key-value storage):

sophia_env *env = sophia_env();
sophia_set(env, "sophia.path", "/tmp/sophia");
sophia_open(env);
int rc = sophia_set(db, "key", "value", 0);

ArangoDB (document storage):

const db = require('arangojs')();
const collection = db.collection('myCollection');
await collection.save({ key: 'value' });
const doc = await collection.document('myKey');

Summary

Sophia is a lightweight key-value store focused on simplicity and performance, while ArangoDB is a feature-rich multi-model database suitable for complex data scenarios. Sophia offers easier integration for basic storage needs, whereas ArangoDB provides more advanced querying and data modeling capabilities at the cost of increased complexity.

4,766

RocksDB/LevelDB inspired key-value database in Go

Pros of Pebble

  • More actively maintained with frequent updates and contributions
  • Better documentation and community support
  • Designed specifically for CockroachDB, optimized for distributed systems

Cons of Pebble

  • Less flexible for general-purpose use cases
  • Potentially more complex to set up and use outside of CockroachDB
  • May have higher resource requirements

Code Comparison

Sophia (key-value storage):

sophia_t *env = sp_env();
sp_setstring(env, "sophia.path", "/tmp/sophia", 0);
sp_open(env);
void *db = sp_getobject(env, "db.test");
sp_set(db, "key", 3, "value", 5);
sp_destroy(env);

Pebble (key-value storage):

db, err := pebble.Open("path/to/db", &pebble.Options{})
if err != nil {
    log.Fatal(err)
}
err = db.Set([]byte("key"), []byte("value"), pebble.Sync)
if err != nil {
    log.Fatal(err)
}
defer db.Close()

Both Sophia and Pebble are key-value storage engines, but they have different focuses and use cases. Sophia is a more general-purpose embedded database, while Pebble is tailored for use in CockroachDB. Pebble offers better performance in distributed environments, while Sophia may be easier to integrate into smaller projects. The code examples show that both provide simple key-value operations, but with different APIs and language preferences.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README



Sophia is advanced transactional MVCC key-value/row storage library.

How does it differ from other storages?

Sophia is RAM-Disk hybrid storage. It is designed to provide best possible on-disk performance without degradation in time. It has guaranteed O(1) worst case complexity for read, write and range scan operations.

It adopts to expected write rate, total capacity and cache size. Memory requirements for common HDD and Flash drives can be seen Here.

What is it good for?

For server environment, which requires lowest latency write and read, predictable behaviour, optimized storage schema and transaction guarantees. It can efficiently work with large volumes of ordered data, such as a time-series, analytics, events, logs, counters, metrics, full-text search, common key-value, etc.

Features

  • Full ACID compliancy
  • MVCC engine
  • Optimistic, non-blocking concurrency with N-writers and M-readers
  • Pure Append-Only
  • Unique data storage architecture
  • Fast: O(1) worst for read, write and range scan operations
  • Multi-threaded compaction
  • Multi-databases support (sharing a single write-ahead log)
  • Multi-Statement and Single-Statement Transactions (cross-database)
  • Serialized Snapshot Isolation (SSI)
  • Optimized storage schema (numeric types has zero-cost storage)
  • Can be used to build Secondary Indexes
  • Upsert (fast write-only 'update or insert' operation)
  • Consistent Cursors
  • Prefix search
  • Automatic garbage-collection
  • Automatic key-expire
  • Hot Backup
  • Compression (no fixed-size blocks, no-holes, supported: lz4, zstd)
  • Direct IO support
  • Use mmap or pread access methods
  • Simple and easy to use (minimalistic API, FFI-friendly, amalgamated)
  • Implemented as small C-written library with zero dependencies
  • Carefully tested
  • Open Source Software, BSD

Support

Sophia Documentation and Bindings for the most common languages are available on the website.

Please use Official Sophia Google Group or StackOverflow to ask any general questions.
More information is available Here.