Skip to content

Commit

Permalink
adding GenerateBlogTable and an import for the authentication package
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkpick committed Jul 16, 2022
1 parent c2c1e3d commit 07dc1c1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/sharkpick/blog

go 1.18

require github.com/sharkpick/authentication v0.0.0-20220710222145-6cb8ef88eda3 // indirect
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
github.com/mattn/go-sqlite3 v1.14.9 h1:10HX2Td0ocZpYEjhilsuo6WWtUqttj2Kb0KtD86/KYA=
github.com/mattn/go-sqlite3 v1.14.9/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/sharkpick/authentication v0.0.0-20220710222145-6cb8ef88eda3 h1:czQNe6fidSIEZfd05uwGfL/mKI729Y5A4sOm7REUjuM=
github.com/sharkpick/authentication v0.0.0-20220710222145-6cb8ef88eda3/go.mod h1:DyPxd3V2kLWWfA91tvLNpSf5UjQXxojU2TkROtJxbjY=
28 changes: 28 additions & 0 deletions schema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package blog

import (
"database/sql"
"fmt"

"github.com/sharkpick/authentication"
)

func GenerateBlogTable(db *sql.DB) error {
sql_string := `CREATE TABLE IF NOT EXISTS "` + BlogEntriesTable + `"(
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"title" TEXT,
"body" TEXT,
"timestamp" TEXT NOT NULL,
"updated" TEXT,
"userid" integer NOT NULL, type int,
FOREIGN KEY(userid) REFERENCES "` + authentication.UsersTable + `"(id));`
prepared, err := db.Prepare(sql_string)
if err != nil {
return fmt.Errorf("GenerateBlogTable %w: %s", ErrUnableToPrepare, err)
}
_, err = prepared.Exec()
if err != nil {
return fmt.Errorf("GenerateBlogTable: %w: %s", ErrUnableToExecute, err)
}
return nil
}

0 comments on commit 07dc1c1

Please sign in to comment.