本文整理汇总了Golang中github.com/jawr/dns/database/connection.Get函数的典型用法代码示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Insert
func (r Record) Insert() error {
conn, err := connection.Get()
if err != nil {
return err
}
args, err := json.Marshal(r.Args)
if err != nil {
return err
}
_, err = conn.Exec(
fmt.Sprintf(`INSERT INTO record__%d_%d
(uuid, domain, name, args, record_type, parser_date, parser) VALUES
($1, $2, $3, $4, $5, $6, $7)`,
r.Type.ID,
r.Domain.TLD.ID,
),
r.UUID.String(),
r.Domain.UUID.String(),
r.Name,
string(args),
r.Type.ID,
r.Date,
r.Parser.ID,
)
return err
}
示例2: Save
func (n *Notification) Save() error {
conn, err := connection.Get()
if err != nil {
return err
}
messages, err := json.Marshal(n.Messages)
if err != nil {
return err
}
archived, err := json.Marshal(n.Archived)
if err != nil {
return err
}
_, err = conn.Exec(
`UPDATE notification SET
messages = $1,
alerts = $2,
archived = $3
WHERE user_id = $4`,
messages,
n.Alerts,
archived,
n.User.ID,
)
return err
}
示例3: NewInsert
func NewInsert(name, table string, args ...string) (Insert, error) {
conn, err := connection.Get()
if err != nil {
return Insert{}, err
}
bi := Insert{}
serial := uniuri.NewLen(5)
bi.name = fmt.Sprintf(name, serial)
bi.table = fmt.Sprintf(table, bi.name)
tx, err := conn.Begin()
if err != nil {
return bi, err
}
// close up our defer tx.Rollback()
bi.tx = tx
_, err = bi.tx.Exec(bi.table)
if err != nil {
return bi, err
}
// prepare args
for idx, i := range args {
args[idx] = fmt.Sprintf(`"%s"`, i)
}
bi.args = args
stmt := fmt.Sprintf(
`COPY %s (%s) FROM STDIN`,
bi.name,
strings.Join(bi.args, ", "),
)
bi.stmt, err = bi.tx.Prepare(stmt)
if err != nil {
return bi, err
}
return bi, nil
}
示例4: New
func New(email, password string) (User, error) {
if u, err := GetByEmail(email).One(); err == nil {
if CheckPassword(email, password) {
return u, nil
}
return User{}, errors.New("Email does not exists, or password does not match.")
}
u := User{}
pass, err := PasswordCrypt([]byte(password))
if err != nil {
return u, err
}
u.Email = email
u.Password = pass
conn, err := connection.Get()
if err != nil {
return u, err
}
var id int32
err = conn.QueryRow("SELECT insert_user($1, $2)", email, pass).Scan(&id)
if err == nil {
u.ID = id
}
return u, err
}
示例5: Get
func Get(query string, args ...interface{}) (Record, error) {
conn, err := connection.Get()
if err != nil {
return Record{}, err
}
row := conn.QueryRow(query, args...)
return parseRow(row)
}
示例6: Finish
func (p *Parser) Finish() error {
conn, err := connection.Get()
if err != nil {
return err
}
t := time.Now()
p.Finished.Time = t
_, err = conn.Exec("UPDATE parser SET finished_at = $1 WHERE id = $2", p.Finished, p.ID)
return err
}
示例7: Get
func Get(query string, args ...interface{}) (Interval, error) {
var result Interval
conn, err := connection.Get()
if err != nil {
return Interval{}, err
}
row := conn.QueryRow(query, args...)
result, err = parseRow(row)
return result, err
}
示例8: Insert
func (r Record) Insert() error {
conn, err := connection.Get()
if err != nil {
return err
}
emails, err := json.Marshal(r.Emails)
if err != nil {
return err
}
data, err := r.Data.MarshalJSON()
if err != nil {
return err
}
raw, err := r.Raw.MarshalJSON()
if err != nil {
return err
}
contacts, err := r.Contacts.MarshalJSON()
if err != nil {
return err
}
organizations, err := json.Marshal(r.Organizations)
if err != nil {
return err
}
phones, err := json.Marshal(r.Phones)
if err != nil {
return err
}
postcodes, err := json.Marshal(r.Postcodes)
if err != nil {
return err
}
names, err := json.Marshal(r.Names)
if err != nil {
return err
}
_, err = conn.Exec(`INSERT INTO whois
(domain, data, raw_whois, contacts, emails, uuid, organizations, phones, postcodes, names)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)`,
r.Domain.UUID.String(),
string(data),
string(raw),
string(contacts),
string(emails),
r.UUID.String(),
string(organizations),
string(phones),
string(postcodes),
string(names),
)
return err
}
示例9: Insert
func (d Domain) Insert() error {
conn, err := connection.Get()
if err != nil {
return err
}
_, err = conn.Exec("INSERT INTO domain (uuid, name, tld) VALUES ($1, $2, $3)",
d.UUID.String(),
d.Name,
d.TLD.ID,
)
return err
}
示例10: New
func New(value string) (Interval, error) {
i := Interval{}
i.Value = value
conn, err := connection.Get()
if err != nil {
return i, err
}
var id int32
err = conn.QueryRow("SELECT insert_interval($1)", value).Scan(&id)
i.ID = id
return i, err
}
示例11: Save
func (p Parser) Save() error {
conn, err := connection.Get()
if err != nil {
return err
}
b, err := json.Marshal(p.Logs)
if err != nil {
return err
}
_, err = conn.Exec("UPDATE parser SET logs = $1 WHERE id = $2", string(b), p.ID)
return err
}
示例12: SetupUserNotification
func SetupUserNotification(user users.User) (Notification, error) {
note := Notification{
User: user,
}
conn, err := connection.Get()
if err != nil {
return note, err
}
_, err = conn.Exec("INSERT INTO notification (user_id) VALUES ($1)", user.ID)
if err != nil {
return note, err
}
return note, nil
}
示例13: Insert
func (p *Parser) Insert() error {
conn, err := connection.Get()
if err != nil {
return err
}
var id int32
err = conn.QueryRow("INSERT INTO parser (filename, parser_date, tld) VALUES ($1, $2, $3) RETURNING id",
p.Filename,
p.Date,
p.TLD.ID,
).Scan(&id)
p.ID = id
return err
}
示例14: New
func New(name string) (TLD, error) {
if tld, ok := byName[name]; ok {
return tld, nil
}
conn, err := connection.Get()
if err != nil {
return TLD{}, err
}
var id int32
err = conn.QueryRow("SELECT insert_tld($1)", name).Scan(&id)
tld := TLD{
ID: id,
Name: name,
}
return tld, err
}
示例15: CheckPassword
func CheckPassword(email, password string) bool {
conn, err := connection.Get()
if err != nil {
return false
}
var pass []byte
err = conn.QueryRow("SELECT password FROM users WHERE email = $1", email).Scan(&pass)
if err != nil {
return false
}
err = bcrypt.CompareHashAndPassword(pass, []byte(password))
if err != nil {
return false
}
return true
}