File: sqlite3.go

package info (click to toggle)
golang-github-anacrolix-missinggo 2.1.0-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 872 kB
  • sloc: makefile: 4
file content (26 lines) | stat: -rw-r--r-- 597 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package runid

import (
	"context"
	"database/sql"

	"github.com/anacrolix/missinggo/expect"
)

type T int64

func New(db *sql.DB) (ret *T) {
	ctx := context.Background()
	conn, err := db.Conn(ctx)
	expect.Nil(err)
	defer func() {
		expect.Nil(conn.Close())
	}()
	_, err = conn.ExecContext(ctx, `CREATE TABLE if not exists runs (started datetime default (datetime('now')))`)
	expect.Nil(err)
	res, err := conn.ExecContext(ctx, "insert into runs default values")
	expect.Nil(err)
	expect.OneRowAffected(res)
	expect.Nil(conn.QueryRowContext(ctx, "select last_insert_rowid()").Scan(&ret))
	return
}