models

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2019 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTenantTable

func CreateTenantTable(dropExistingTable bool)

*

  • Function will create the `tenants` table in the database.

func CreateUserTable

func CreateUserTable(dropExistingTable bool)

*

  • Function will create the `users` table in the database.

func InitDB

func InitDB(dbHost, dbPort, dbUser, dbPassword, dbName string) *sqlx.DB

*

  • Function initializes our connection with the `postgres` database for this
  • web-application and saves the db connection instance in a global variable.

Types

type Tenant

type Tenant struct {
	Id     uint64         `db:"id"`
	Schema sql.NullString `db:"schema"`
	Name   sql.NullString `db:"name"`
}

func CreateTenant

func CreateTenant(schema string, name string) (*Tenant, error)

*

  • Function will create a tenant, if validation passess, and reutrns the `tenant`
  • struct else returns the error.

func FetchTenants

func FetchTenants(page uint64, pageSize uint64) ([]Tenant, uint64)

*

  • Function will return paginated list of tenants.

func FindTenantById

func FindTenantById(id uint64) (*Tenant, error)

*

  • Function will return the `tenant` struct if it exists in the database or
  • return an error.

func FindTenantBySchema

func FindTenantBySchema(schema string) (*Tenant, error)

*

  • Function will return the `tenant` struct if it exists in the database or
  • return an error.

type User

type User struct {
	TenantId     int64          `db:"tenant_id"`
	TenantSchema sql.NullString `db:"tenant_schema"`
	Id           int64          `db:"id"`
	FirstName    sql.NullString `db:"first_name"`
	LastName     sql.NullString `db:"last_name"`
	PasswordHash sql.NullString `db:"password_hash"`
	Email        sql.NullString `db:"email"`
	GroupId      uint8          `db:"group_id"`
}

func CreateUser

func CreateUser(email string, firstName string, lastName string, password string, tenantId int64, tenantSchema string, groupId int64) (*User, error)

*

  • Function will create a user, if validation passess, and reutrns the `user`
  • struct else returns the error.

func FindUserByEmail

func FindUserByEmail(email string) (*User, error)

*

  • Function will return the `user` struct if it exists in the database or
  • return an error.

Jump to

Keyboard shortcuts

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