eXtremeDB Timestamps Usage

This functionality is available in eXtremeDB starting with version 9.0.

Timestamps allow you to automatically record the creation or modification time of a database record.

eXtremeDB supports timestamps at the kernel level and implements this functionality through its built-in event mechanism. In the schema, class fields can be marked with the on_create or on_update keywords. When on_create is specified, the field is automatically populated with the system time (the result of calling mco_system_get_current_time()) at the moment the object is created. When on_update is specified, the field is updated with the current system time whenever the object is modified. The mcocomp schema compiler automatically generates the required on-new and on-update event handlers; the application only needs to call the generated registration function <dbname>_register_time_events().

Fields marked with on_create or on_update can be used in indexes like any other field. However, note the following:

An example of timestamp field definitions in a schema:

    #define int1      signed<1>
    #define int2      signed<2>
    #define int4      signed<4>
    #define int8      signed<8>
    #define uint8     unsigned<8>
    #define uint4     unsigned<4>
    #define uint2     unsigned<2>
    #define uint1     unsigned<1>

    declare database tmdb;

    class MyClass
    {
        uint4 key;
        uint4 payload;
        on_create datetime ctime;
        on_update datetime mtime;

        hash <key> pk[1000];
        tree <ctime> created;
        tree <mtime> updated;
    };
            

A working code example demonstrating this mechanism is located in the samples/native/core/10-events/obj-timestamps directory.

For more information about using events in eXtremeDB, see the Using eXtremeDB Database Events and Time-To-Live Features page.