Skip to content

Commit

Permalink
fix image generation insertion with postgres
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Feb 19, 2024
1 parent b185623 commit 4083b16
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
19 changes: 4 additions & 15 deletions lib/Db/Text2Image/ImageGeneration.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
* @method \void setUserId(string $userId)
* @method \int getTimestamp()
* @method \void setTimestamp(int $timestamp)
* @method \boolean getIsGenerated()
* @method \void setIsGenerated(bool $isGenerated)
* @method \boolean getFailed()
* @method \void setFailed(bool $failed)
* @method \boolean getNotifyReady()
* @method \void setNotifyReady(bool $notifyReady)
* @method \int getExpGenTime()
Expand Down Expand Up @@ -67,19 +71,4 @@ public function jsonSerialize() {
'exp_gen_time' => $this->expGenTime,
];
}

public function setIsGenerated(?bool $isGenerated): void {
$this->isGenerated = $isGenerated === true;
}
public function getIsGenerated(): bool {
return $this->isGenerated === true;
}

public function setFailed(?bool $failed): void {
$this->failed = $failed === true;
}

public function getFailed(): bool {
return $this->failed === true;
}
}
43 changes: 33 additions & 10 deletions lib/Db/Text2Image/ImageGenerationMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,39 @@ public function createImageGeneration(
string $imageGenId, string $prompt = '', string $userId = '', ?int $expCompletionTime = null,
bool $notifyReady = false
): ImageGeneration {
$imageGeneration = new ImageGeneration();
$imageGeneration->setImageGenId($imageGenId);
$imageGeneration->setTimestamp((new DateTime())->getTimestamp());
$imageGeneration->setPrompt($prompt);
$imageGeneration->setUserId($userId);
$imageGeneration->setIsGenerated(false);
$imageGeneration->setFailed(false);
$imageGeneration->setNotifyReady($notifyReady);
$imageGeneration->setExpGenTime($expCompletionTime ?? (new DateTime())->getTimestamp());
return $this->insert($imageGeneration);
$nowTimestamp = (new DateTime())->getTimestamp();

$qb = $this->db->getQueryBuilder();
$qb->insert($this->getTableName())
->values([
'image_gen_id' => $qb->createNamedParameter($imageGenId, IQueryBuilder::PARAM_STR),
'timestamp' => $qb->createNamedParameter($nowTimestamp, IQueryBuilder::PARAM_INT),
'prompt' => $qb->createNamedParameter($prompt, IQueryBuilder::PARAM_STR),
'user_id' => $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR),
'is_generated' => $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL),
'failed' => $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL),
'notify_ready' => $qb->createNamedParameter($notifyReady, IQueryBuilder::PARAM_BOOL),
'exp_gen_time' => $qb->createNamedParameter($expCompletionTime ?? $nowTimestamp, IQueryBuilder::PARAM_INT),
]);
$qb->executeStatement();
$qb->resetQueryParts();

return $this->getImageGenerationOfImageGenId($imageGenId);

// TODO figure out why inserting an entity does not work on PostgreSQL and produces:
// An exception occurred while executing a query: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type boolean: \"\""
// could there be a bug in the query generation?
//$imageGeneration = new ImageGeneration();
//$imageGeneration->setImageGenId($imageGenId);
//$imageGeneration->setTimestamp((new DateTime())->getTimestamp());
//$imageGeneration->setPrompt($prompt);
//$imageGeneration->setUserId($userId);
//$imageGeneration->setIsGenerated(false);
//$imageGeneration->setFailed(false);
//$imageGeneration->setNotifyReady($notifyReady);
//$imageGeneration->setExpGenTime($expCompletionTime ?? (new DateTime())->getTimestamp());
//return $this->insert($imageGeneration);
}

/**
Expand Down

0 comments on commit 4083b16

Please sign in to comment.