Connection.nest

The method inserts records

For an overview see page Python Connection Class

Prototype

    Connection.nest(“classname”, records)
    # or
    Connection.nest(classobj, records)
 

Arguments

className
A string containing the class name as defined in the database schema.
classObj
A database dictionary class object representing the target class. It can be obtained, for example, as follows:
    quote_class = db.getDict().classes['Quote']
records
specifies the data to insert and may be:
  • tuple, then proceed with only 1 object/record
  • class, then proceed with only 1 object/record with field matching
  • list of tuples, then proceed with many objects/records. Perform transpose
  • list of classes, proceed with many objects/records. Perform transpose after field matching

Description

In many cases, application logic does not operate directly on objects when inserting records, or records must be distributed across multiple objects. To support these scenarios, the Connection object provides the nest() method, which behaves similarly to Object.seq_append() but does not require an existing object.

Field Matching Rules for Connection.nest()

Stricter rules apply compared to Object.seq_append():

Processing Steps:

For a Connection.nest() call, the following steps are performed:

The method is available since eXtremeDB version 8.4.1806.

Example

    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 timeseries;


    class Obj {
        int4 key;
        sequence<int4> s1;
        sequence<float> s2;
        sequence<int8 asc> s3;

        unique tree<key> by_key;
    };
    """

    ...

    class MyObj:
    def __init__(self, key, s1, s2, s3):
        self.key = key
        self.s1 = s1
        self.s2 = s2
        self.s3 = s3

    ...

    con.startTransaction(exdb.Transaction.MCO_READ_WRITE)

    con.nest("Obj", (43, 11, 12, 13))
    con.nest("Obj", [(43, 12, 13, 14), (43, 13, 14, 15)])

    dict_obj = con.db.getDict().classes['Obj']
    con.nest(dict_obj, MyObj(43, 14, 15, 16))

    # Use a list of objects, and use different object instances.
    # Append to object 43 and create object 44
    con.nest(dict_obj, [(43, 15, 16, 17), (44, 16, 17, 18)])

    con.commit()