Documentation
¶
Overview ¶
All the error codes can be found here: https://www.postgresql.org/docs/current/errcodes-appendix.html
Index ¶
- Constants
- func Close() error
- func Connect(dbUrl string) error
- func DeleteEmailVerificationWithUserId(uid string) (sql.Result, error)
- func ExistsUserWithEmail(email string) (bool, error)
- func Ping() error
- func SaveBentoEntryBatch(entries []BentoEntry) error
- func StartTx() (*sql.Tx, error)
- type Bento
- type BentoEntry
- type EmailVerification
- type Model
- type User
Constants ¶
const ( EMAIL_VERIFICATION_CODE_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" EMAIL_VERIFICATION_CODE_LENGTH = 20 )
const (
PG_ERR_UNIQUE_VIOLATION = "unique_violation"
)
Class 23 - Integrity Constraint Violation
Variables ¶
This section is empty.
Functions ¶
func Close ¶
func Close() error
Close closes the database connection. Not intended to be used in production, but makes testing easier.
func Connect ¶
Connect establishes a connection with the given postgresql database with the given url.
func DeleteEmailVerificationWithUserId ¶
DeleteEmailVerificationWithUserId tries to removes any email verification code that has the given user id. IMPORTANT: this method does not use a transaction so deletion are UNSAFE.
func ExistsUserWithEmail ¶
ExistsUserWithEmail checks if there is a user with the given email stored in the database.
func Ping ¶
func Ping() error
Ping makes sure that connection is still alives. It context.Background and timeouts in 5 seconds.
func SaveBentoEntryBatch ¶
func SaveBentoEntryBatch(entries []BentoEntry) error
SaveBentoEntryBatch will save a batch of BentoEntry at once. The entries will be updated in place with the corresponding id, created_at and updated_at from the database.
Types ¶
type Bento ¶
type Bento struct { Id string Name string OwnerId string PubKey string CreatedAt time.Time UpdatedAt time.Time }
Bento represents a bento object that has a slice with all the entries as well.
func GetBentoWithId ¶
GetBentoWithId retrieves a bento with the given id.
func NewBento ¶
NewBento will create and save a new bento into the database with the given information. This method will return an error if there is another bento with the same name from the same user. All bentos belonging to one user should have unique names.
type BentoEntry ¶
type BentoEntry struct { Id int64 Name string Value string BentoId string CreatedAt time.Time UpdatedAt time.Time }
BentoEntry represents an entry (secret) of a already preprared bento in the database.
func GetEntriesForBento ¶
func GetEntriesForBento(bentoId string) ([]BentoEntry, error)
GetEntriesForBento will get all the entries for a given bento.
func NewBentoEntry ¶
func NewBentoEntry(name, value, bentoId string) BentoEntry
NewBentoEntry just creates a new BentoEntry struct and it DOES NOT saves it in the database. This allows any procedure to create multiple BentoEntry if needed and save them in a batch.
type EmailVerification ¶
type EmailVerification struct { Id int64 Code string UserId string ExpiresAt time.Time CreatedAt time.Time }
EmailVerification represents an email verification record in the database.
func GetEmailVerificationWithCode ¶
func GetEmailVerificationWithCode(code string) (*EmailVerification, error)
GetEmailVerificationWithCode tries to retrieves an email verification record from the database with the given code.
func NewEmailVerification ¶
func NewEmailVerification(userId string) (*EmailVerification, error)
NewEmailVerification creates a new email verification record.
type User ¶
type User struct { Id string Email string Password string Name string EmailVerified bool CreatedAt time.Time UpdatedAt time.Time }
User represents a real user store in the database.
func GetUserWithEmail ¶
GetUserWithEmail retrieves a user in the database with the given email.
func GetUserWithEmailAndPassword ¶
GetUserWithEmailAndPassword tries to match a user with the given email and password. Usage for signining a user. Its better to use psql to match the password in the query.
func GetUserWithId ¶
GetUserWithId retrieves a user with the given id. An error is returned if nothing is found.
func NewUser ¶
NewUser creates a new user with the given information. This function will save the new user in the database.