Insert a node with a name and optional value. Return the node id.

def insert_node(**kw):
    "Insert a node with a name and optional value. Return the node id."
    with current_app.app_context():
        result = db.execute(text(fetch_query_string('insert_node.sql')), **kw)
        # TODO: support for postgres may require using a RETURNING id; sql
        # statement and using the inserted_primary_key?
        #node_id = result.inserted_primary_key
        node_id = result.lastrowid
        if (not node_id):
            result = result.fetchall()
            node_id = result[0]['id']
        return node_id