protected function _processCreate(Query $query, array $options = []) {
        $data = $query->getData();
        $options = $options + [
            'before' => true,
            'after' => true
        ];

        if ($options['before']) {
            foreach (['db.preSave', 'db.preCreate'] as $event) {
                $event = $this->emit($event, [$query, null, &$data]);

                if (!$event->getState()) {
                    return 0;
                }
            }
        }

        // Reset the modified data
        $query->data($data);

        // Update the connection context
        $driver = $this->getDriver();
        $driver->setContext('write');

        // Execute the query
        $count = $driver->executeQuery($query)->save();

        // Exit early if save failed
        if ($count === false) {
            return 0;
        }

        $id = $driver->getLastInsertID($this);

        if ($options['after']) {
            $this->emit('db.postSave db.postCreate', [$id, $count]);
        }

        return $this->id = $id;
    }