hm sqlite transactions dont play with begin commit
parent
b85df7bd31
commit
e6d9e356ca
|
|
@ -196,22 +196,21 @@ func (f *Feeds) oldGet(ctx context.Context, id string) (Feed, error) {
|
||||||
func (f *Feeds) Insert(ctx context.Context, url, cron string) (string, error) {
|
func (f *Feeds) Insert(ctx context.Context, url, cron string) (string, error) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
id := uuid.New().String()
|
id := uuid.New().String()
|
||||||
q := `
|
return id, db.Exec(ctx, `
|
||||||
BEGIN;
|
BEGIN;
|
||||||
INSERT INTO "feed.entries" (
|
INSERT INTO "feed.entries" (
|
||||||
id,
|
id,
|
||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
) VALUES (?, ?, ?);
|
) VALUES ($1, $2, $3);
|
||||||
INSERT INTO "feed.versions" (
|
INSERT INTO "feed.versions" (
|
||||||
entries_id,
|
entries_id,
|
||||||
created_at,
|
created_at,
|
||||||
url,
|
url,
|
||||||
cron
|
cron
|
||||||
) VALUES (?, ?, ?, ?);
|
) VALUES ($4, $5, $6, $7);
|
||||||
COMMIT;
|
COMMIT;
|
||||||
`
|
`,
|
||||||
return id, db.Exec(ctx, q,
|
|
||||||
id, now, now,
|
id, now, now,
|
||||||
id, now, url, cron,
|
id, now, url, cron,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,36 @@ func TestFeeds(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("cannot get:", err)
|
t.Fatal("cannot get:", err)
|
||||||
}
|
}
|
||||||
t.Errorf("%+v", got)
|
t.Logf("%+v", got)
|
||||||
|
|
||||||
|
if got.Entry.ID == "" {
|
||||||
|
t.Error("no entry.id")
|
||||||
|
}
|
||||||
|
if got.Entry.Created.IsZero() {
|
||||||
|
t.Error("no entry.created")
|
||||||
|
}
|
||||||
|
if got.Entry.Updated.IsZero() {
|
||||||
|
t.Error("no entry.updated")
|
||||||
|
}
|
||||||
|
if !got.Entry.Deleted.IsZero() {
|
||||||
|
t.Error("entry.deleted")
|
||||||
|
}
|
||||||
|
|
||||||
|
if got.Version.Created.IsZero() {
|
||||||
|
t.Error("no version.created")
|
||||||
|
}
|
||||||
|
if got.Version.URL != "url" {
|
||||||
|
t.Error("no version.url")
|
||||||
|
}
|
||||||
|
if got.Version.Cron != "cron" {
|
||||||
|
t.Error("no version.cron")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !got.Execution.Executed.IsZero() {
|
||||||
|
t.Error("execution.executed")
|
||||||
|
}
|
||||||
|
if !got.Execution.Version.IsZero() {
|
||||||
|
t.Error("execution.version")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue