本文整理汇总了Golang中github.com/jawr/dns/database/connection.Get函数的典型用法代码示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Get函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:grunya404,项目名称:dns,代码行数:26,代码来源:records.go
示例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
}
开发者ID:grunya404,项目名称:dns,代码行数:26,代码来源:notifications.go
示例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
}
开发者ID:grunya404,项目名称:dns,代码行数:35,代码来源:bulk.go
示例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
}
开发者ID:grunya404,项目名称:dns,代码行数:25,代码来源:users.go
示例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)
}
开发者ID:grunya404,项目名称:dns,代码行数:8,代码来源:get.go
示例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
}
开发者ID:grunya404,项目名称:dns,代码行数:10,代码来源:parser.go
示例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
}
开发者ID:grunya404,项目名称:dns,代码行数:10,代码来源:get.go
示例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
}
开发者ID:grunya404,项目名称:dns,代码行数:54,代码来源:whois.go
示例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
}
开发者ID:grunya404,项目名称:dns,代码行数:12,代码来源:domain.go
示例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
}
开发者ID:grunya404,项目名称:dns,代码行数:12,代码来源:intervals.go
示例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
}
开发者ID:grunya404,项目名称:dns,代码行数:12,代码来源:parser.go
示例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
}
开发者ID:grunya404,项目名称:dns,代码行数:15,代码来源:notifications.go
示例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
}
开发者ID:grunya404,项目名称:dns,代码行数:15,代码来源:parser.go
示例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
}
开发者ID:grunya404,项目名称:dns,代码行数:16,代码来源:tld.go
示例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
}
开发者ID:grunya404,项目名称:dns,代码行数:16,代码来源:users.go
示例16: newResult
func newResult(query string, args ...interface{}) Result {
return Result{
func() (int, error) {
var count int
conn, err := connection.Get()
if err != nil {
return count, err
}
query = strings.Replace(query, "SELECT *", "SELECT COUNT(*)", 1)
err = conn.QueryRow(query, args...).Scan(&count)
return count, err
},
func() (Record, error) {
return Get(query, args...)
},
func() ([]Record, error) {
return GetList(query, args...)
},
}
}
开发者ID:grunya404,项目名称:dns,代码行数:20,代码来源:get.go
示例17: GetList
func GetList(query string, args ...interface{}) ([]Record, error) {
conn, err := connection.Get()
if err != nil {
return []Record{}, err
}
rows, err := conn.Query(query, args...)
defer rows.Close()
if err != nil {
return []Record{}, err
}
var list []Record
for rows.Next() {
rt, err := parseRow(rows)
if err != nil {
return list, err
}
list = append(list, rt)
}
return list, rows.Err()
}
开发者ID:grunya404,项目名称:dns,代码行数:20,代码来源:get.go
示例18: Save
func (w *Watcher) Save() error {
conn, err := connection.Get()
if err != nil {
return err
}
w.Logs = append(w.Logs, Log{w.Updated})
w.Updated = time.Now()
b, err := json.Marshal(w.Logs)
if err != nil {
return err
}
var usersArr []int32
for _, u := range w.Users {
usersArr = append(usersArr, u.ID)
}
b2, err := json.Marshal(usersArr)
if err != nil {
return err
}
_, err = conn.Exec("UPDATE watcher SET updated = $1, logs = $2, users = $3 WHERE id = $4", w.Updated, b, b2, w.ID)
return err
}
开发者ID:grunya404,项目名称:dns,代码行数:22,代码来源:watchers.go
示例19: New
func New(name string, tld tlds.TLD) (Type, error) {
if _, ok := byNameAndTLD[name]; ok {
if t, ok := byNameAndTLD[name][tld.ID]; ok {
return t, nil
}
}
conn, err := connection.Get()
if err != nil {
return Type{}, err
}
var id int32
err = conn.QueryRow("SELECT ensure_record_table($1, $2)", name, tld.ID).Scan(&id)
rt := Type{
ID: id,
Name: name,
}
if err == nil {
if _, ok := byNameAndTLD[name]; !ok {
byNameAndTLD[name] = make(map[int32]Type)
}
byNameAndTLD[name][tld.ID] = rt
}
return rt, err
}
开发者ID:grunya404,项目名称:dns,代码行数:24,代码来源:types.go
示例20: New
func New(d domains.Domain, interval string) (Watcher, error) {
w := Watcher{}
w.Domain = d
i, err := intervals.New(interval)
if err != nil {
// TODO: better wrapper for our db errors so can see in log which package
return w, err
}
w.Interval = i
w.Updated = time.Now()
w.Added = time.Now()
conn, err := connection.Get()
if err != nil {
return w, err
}
err = conn.QueryRow("INSERT INTO watcher (domain, interval) VALUES ($1, $2) RETURNING id",
d.UUID.String(),
i.ID,
).Scan(&w.ID)
if err != nil {
return w, err
}
return GetByDomain(d).One()
}
开发者ID:grunya404,项目名称:dns,代码行数:24,代码来源:watchers.go
注:本文中的github.com/jawr/dns/database/connection.Get函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论