fix: Unique ID doesn't fail at first try

Fixes #3

Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
Julien Riou 2025-08-24 15:15:16 +02:00
parent 711327390f
commit e22105049a
Signed by: jriou
GPG key ID: 9A099EDA51316854

View file

@ -29,11 +29,10 @@ func (n *Note) BeforeCreate(tx *gorm.DB) (err error) {
id := internal.GenerateChars(idLength)
var note *Note
tx.Where("id = ?", id).Scan(&note)
var note Note
tx.Where("id = ?", id).Find(&note)
// TODO: time=2025-08-21T09:20:31.342+02:00 level=ERROR msg="could not create note" error="UNIQUE constraint failed: notes.id"
if note == nil {
if note.ID == "" {
n.ID = id
continue
}