/** * truncate given schema (clear all data, even if it has relations) * * @param ISchema $schema */ public function truncate(ISchema $schema) { $this->connected(); $result = $this->pdo->prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name=?;"); $result->execute([$schema->getName()]); if ($result->fetch() !== false) { $this->pdo->exec('DELETE FROM ' . $this->delimite($schema->getName())); } }
/** * create the table from the given schema; this method needs to be optimized * * @param ISchema $schema * * @return $this */ public function createSchema(ISchema $schema) { if ($this->cache->load($cacheId = 'schema.' . $schema->getName()) === true) { return $this; } $createTableQuery = new CreateTableQuery($schema); $createTableQuery->setIfNotExists(); $createTableQuery->addColumn(new ColumnFragment($this->createPrimaryProperty())); $this->exec($createTableQuery); $this->cache->save($cacheId, true); return $this; }