typemap


Description:

public HashMap<string,Type>? typemap

Typemap for polymorphic deserialization.

Maps type identifier strings (e.g., "p", "f", "d") to GObject types. This allows Query to instantiate the correct subclass when deserializing from a database table that stores multiple types in a single table.

**Why this is needed:**

When you have a base class (e.g., `FileBase`) with multiple subclasses (e.g., `File`, `Folder`, `Project`), and all are stored in the same database table, SQLite can only return generic rows. Without type information, you cannot know which subclass to instantiate when deserializing.

**How it works:**

1. The database table must include a column (specified by `typekey`) that stores a type identifier string (e.g., "p" for Project, "f" for File, "d" for Folder).

2. Before executing a query, you populate `typemap` with mappings from these identifier strings to the actual GObject types.

3. When `selectExecute` processes each row, it reads the type identifier from the `typekey` column, looks it up in `typemap`, and instantiates the correct subclass instead of the base class.

**Example:**

// Database table: files
// Columns: id, path, parent_id, base_type, ...
// base_type column contains: "p", "f", or "d"

var query = new SQ.Query<FileBase>(db, "files");

// Set up polymorphic type mapping
query.typemap = new Gee.HashMap<string, Type>();
query.typemap["p"] = typeof(Project);
query.typemap["f"] = typeof(File);
query.typemap["d"] = typeof(Folder);
query.typekey = "base_type"; // Column name containing type identifier

// Now when you query, each row will be instantiated as the correct subclass
var results = new Gee.ArrayList<FileBase>();
query.select("parent_id = ?", results);
// Results will contain Project, File, and Folder instances as appropriate

**Important:**

- The `typekey` column must exist in the SELECT query results - The type identifier values in the database must match the keys in `typemap` - If a type identifier is not found in `typemap`, the base type `T` will be used - This only affects object instantiation; property mapping works the same way