技术控

    今日:0| 主题:63445
收藏本版 (1)
最新软件应用技术尽在掌握

[其他] upper.io - database access

[复制链接]
海岛陌安逝暮梦 发表于 2016-11-30 03:10:07
178 0
upper.io/db.v2         

  The    upper.io/db.v2package for    Gois    notan ORM, it's just a productive data access layer for Go which provides a common interface to work with different data sources such as    PostgreSQL,    MySQL,    SQLite,    QLand    MongoDB.  
  1. go get upper.io/db.v2
复制代码
User documentation

  This is the source code repository, see examples and documentation at    upper.io/db.v2.  
  Demo

  You can run the following example on our    playground:  
  1. package main
  2. import (
  3.     "log"
  4.     "upper.io/db.v2/postgresql"
  5. )
  6. var settings = postgresql.ConnectionURL{
  7.     Host:     "demo.upper.io",
  8.     Database: "booktown",
  9.     User:     "demouser",
  10.     Password: "demop4ss",
  11. }
  12. type Book struct {
  13.     ID        int    `db:"id"`
  14.     Title     string `db:"title"`
  15.     AuthorID  int    `db:"author_id"`
  16.     SubjectID int    `db:"subject_id"`
  17. }
  18. func main() {
  19.     sess, err := postgresql.Open(settings)
  20.     if err != nil {
  21.         log.Fatalf("db.Open(): %q\n", err)
  22.     }
  23.     defer sess.Close()
  24.     var books []Book
  25.     err = sess.Collection("books").Find().All(&books)
  26.     if err != nil {
  27.         log.Fatalf("Find(): %q\n", err)
  28.     }
  29.     for i, book := range books {
  30.         log.Printf("Book %d: %#v\n", i, book)
  31.     }
  32. }
复制代码
Or you can also run it locally from the    _examplesdirectory:  
  1. go run _examples/booktown-books/main.go
  2. 2016/08/10 08:42:48 "The Shining" (ID: 7808)
  3. 2016/08/10 08:42:48 "Dune" (ID: 4513)
  4. 2016/08/10 08:42:48 "2001: A Space Odyssey" (ID: 4267)
  5. 2016/08/10 08:42:48 "The Cat in the Hat" (ID: 1608)
  6. 2016/08/10 08:42:48 "Bartholomew and the Oobleck" (ID: 1590)
  7. 2016/08/10 08:42:48 "Franklin in the Dark" (ID: 25908)
  8. 2016/08/10 08:42:48 "Goodnight Moon" (ID: 1501)
  9. 2016/08/10 08:42:48 "Little Women" (ID: 190)
  10. 2016/08/10 08:42:48 "The Velveteen Rabbit" (ID: 1234)
  11. 2016/08/10 08:42:48 "Dynamic Anatomy" (ID: 2038)
  12. 2016/08/10 08:42:48 "The Tell-Tale Heart" (ID: 156)
  13. 2016/08/10 08:42:48 "Programming Python" (ID: 41473)
  14. 2016/08/10 08:42:48 "Learning Python" (ID: 41477)
  15. 2016/08/10 08:42:48 "Perl Cookbook" (ID: 41478)
  16. 2016/08/10 08:42:48 "Practical PostgreSQL" (ID: 41472)
复制代码
License

  This project is licensed under the terms of the    MIT License.  
    Copyright (c) 2012-present The upper.io/db authors. All rights reserved.
    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    Authors and contributors

  
我要投稿

推荐阅读


回页顶回复上一篇下一篇回列表
手机版/c.CoLaBug.com ( 粤ICP备05003221号 | 粤公网安备 44010402000842号 )

© 2001-2017 Comsenz Inc.

返回顶部 返回列表