-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding GenerateBlogTable and an import for the authentication package
- Loading branch information
Showing
3 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |