simple_persist

SCOOP-Safe Object Persistence for Eiffel

Eiffel MIT Tests

Overview

simple_persist is a lightweight object persistence library for Eiffel providing binary serialization, in-memory object chains, fluent queries, and hash-based indexing.

Binary Serialization

Efficient binary format with SP_WRITER and SP_READER for primitives, strings, and custom objects.

Object Chains

In-memory collections with cursor navigation, soft delete, and file persistence.

Fluent Queries

Builder pattern for filtering with where(), pagination with take()/skip(), and ordering.

Hash Indexing

Fast key-based lookups with automatic index maintenance and multi-value support.

Design by Contract

Full preconditions, postconditions, and invariants for reliable code.

SCOOP Compatible

Safe for concurrent access in SCOOP-enabled applications.

Quick Start

Installation

<library name="simple_persist" location="$SIMPLE_LIBS\simple_persist\simple_persist.ecf"/>

Define a Storable Object

class MY_ITEM inherit SP_STORABLE

feature
    name: STRING_32
    value: INTEGER

    store (writer: SP_WRITER)
        do
            writer.put_string (name)
            writer.put_integer_32 (value)
        end

    retrieve (reader: SP_READER)
        do
            name := reader.read_string
            value := reader.read_integer_32
        end
end

Create and Persist

local
    chain: SP_ARRAYED_CHAIN [MY_ITEM]
    item: MY_ITEM
do
    create chain.make
    create item.make_default
    item.name := "Test"
    item.value := 42
    chain.extend (item)
    chain.save_as ("data.bin")
end

API Reference

Class Purpose Key Features
SIMPLE_PERSIST Facade file_exists, delete_file, version
SP_WRITER Serialization put_integer_*, put_string, put_boolean, to_file
SP_READER Deserialization read_integer_*, read_string, read_boolean, from_file
SP_CHAIN Base chain save, load, mark_deleted, compact
SP_ARRAYED_CHAIN Array chain extend, remove, item, start/forth/back/finish
SP_STORABLE Base object store, retrieve, is_deleted
SP_QUERY Query builder where, and_where, or_where, take, skip, results
SP_HASH_INDEX Hash index items_for_key, first_for_key, on_extend, on_remove

Examples

Querying with Conditions

local
    query: SP_QUERY [MY_ITEM]
    results: LIST [MY_ITEM]
do
    create query.make (chain)
    results := query
        .where (agent (it: MY_ITEM): BOOLEAN do Result := it.value > 10 end)
        .and_where (agent (it: MY_ITEM): BOOLEAN do Result := it.name.has_substring ("test") end)
        .take (50)
        .skip (10)
        .results
end

Using Indexes

local
    index: SP_HASH_INDEX [MY_ITEM, STRING_32]
    items: LIST [MY_ITEM]
do
    create index.make ("name_idx", agent (it: MY_ITEM): STRING_32 do Result := it.name end)

    -- Register items
    across chain as ic loop
        index.on_extend (ic.item)
    end

    -- Fast lookup
    items := index.items_for_key ("Alpha")
end