app

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2025 License: Unlicense Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindTime

func BindTime(v time.Time) int64

func Must

func Must(c bool, format string, a ...any)

func MustBe

func MustBe(c bool)

func MustBeEqual

func MustBeEqual(a, b any)

func MustBeNil

func MustBeNil(a any)

func MustBeSet

func MustBeSet(a any)

func Run

func Run(makeDb func(dbfile string) Db)

func UnbindTime

func UnbindTime(v int64) time.Time

Types

type Article

type Article struct {
	Id      int
	Created time.Time
	UserId  int // the user that wrote this article
	Text    string
}

Articles are created by Users.

func NewArticle

func NewArticle(id int, created time.Time, userId int, text string) Article

type Comment

type Comment struct {
	Id        int
	Created   time.Time
	ArticleId int // the article that this comment is for
	Text      string
}

Comments are written for Articles.

func NewComment

func NewComment(id int, created time.Time, articleId int, text string) Comment

type Db

type Db interface {
	DriverName() string
	Exec(sqls ...string)
	InsertUsers(insertSql string, users []User)
	InsertArticles(insertSql string, articles []Article)
	InsertComments(insertSql string, comments []Comment)
	FindUsers(querySql string) []User
	FindUsersArticlesComments(querySql string) ([]User, []Article, []Comment)
	Close()
}

Db is the database interface.

type SqlDb

type SqlDb struct {
	// contains filtered or unexported fields
}

SqlDb is a Db implementation that uses database/sql package.

func NewSqlDb

func NewSqlDb(driverName string, db *sql.DB) *SqlDb

func (*SqlDb) Close

func (d *SqlDb) Close()

func (*SqlDb) DriverName

func (d *SqlDb) DriverName() string

func (*SqlDb) Exec

func (d *SqlDb) Exec(sqls ...string)

func (*SqlDb) FindArticles

func (d *SqlDb) FindArticles(querySql string) []Article

func (*SqlDb) FindUsers

func (d *SqlDb) FindUsers(querySql string) []User

func (*SqlDb) FindUsersArticlesComments

func (d *SqlDb) FindUsersArticlesComments(querySql string) ([]User, []Article, []Comment)

func (*SqlDb) InsertArticles

func (d *SqlDb) InsertArticles(insertSql string, articles []Article)

func (*SqlDb) InsertComments

func (d *SqlDb) InsertComments(insertSql string, comments []Comment)

func (*SqlDb) InsertUsers

func (d *SqlDb) InsertUsers(insertSql string, users []User)

type User

type User struct {
	Id      int
	Created time.Time
	Email   string
	Active  bool
}

User is a registered User who can access the blog.

func NewUser

func NewUser(id int, created time.Time, email string, active bool) User

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL