aboutsummaryrefslogtreecommitdiff
path: root/src/server/database/post.go
blob: d73344a0aa6183744d9410351fdf53cad0a2c43e (plain)
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
27
28
package database

import (
	"time"
)

// Writes a post to the database, returns the uid of the new post.
func WritePost(author int,
	parent *int,
	title string,
	contents string,
	subreact string,
	image []byte,
	thumbnail []byte) (int, error) {

	var db = GetDb()

	var uid int
	row := db.QueryRow("INSERT INTO Posts "+
		"(author, parent, time, subreact, title, contents, thumbnail, image) "+
		"VALUES(?, ?, ?, ?, ?, ?, ?, ?) RETURNING Posts.uid;",
		author, parent, time.Now().Unix(), subreact, title, contents, thumbnail, image)
	if err := row.Scan(&uid); err != nil {
		return 0, err
	}

	return uid, nil
}