tiny-url-ex/service/shortener/model.go

32 lines
573 B
Go
Raw Normal View History

package shortener
import (
"database/sql"
"context"
"git.xdrm.io/example/aicra/storage"
)
// tinyModel represents an actual tiny url entry in the database.
type tinyModel BadExpr
BadDecl
type repository struct {
db *sql.DB
}
// newRepo returns an initialized repository.
func newRepo(db *sql.DB) (*model, error) {
log.Printf("[service.shortener] creating repository")
res, err := db.Exec(ctx, `CREATE TABLE if not exist tiny(
tiny varchar(30) PRIMARY,
target varchar(300) NOT NULL,
)`)
if err != nil {
return nil, err
}
return &repository{ctx, db}
}