Пример #1
0
func main2() {
	qbs.Register("sqlite3", "gowalker.db", "", qbs.NewSqlite3())

	q, _ := qbs.GetQbs()
	defer q.Close()

	pinfo := new(PkgInfo)
	q.Iterate(pinfo, func() error {

		if pinfo.Id > 198 {
			c := &http.Client{}
			req, err := http.NewRequest("GET",
				"http://gowalker.org/add?path="+pinfo.Path+"&views="+fmt.Sprintf("%d", pinfo.Views), nil)
			if err != nil {
				return err
			}
			req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0")
			resp, err := c.Do(req)
			defer resp.Body.Close()

			fmt.Println(pinfo.Id, pinfo.Path)
			if pinfo.Id >= 10000 {
				return errors.New("FINISH")
			}
		}
		return nil
	})
}
Пример #2
0
func RegisterDb() {
	err := os.MkdirAll("./data", 777)
	if err != nil {
		fmt.Println(err)

	}
	qbs.Register("sqlite3", "./data/ubuntu_log.sqlite", "./data/ubuntu_log.sqlite", qbs.NewSqlite3())
}
Пример #3
0
//StringToDialect returns an sql dialect for use with QBS given a string
//name.  IF the name is not known, this code panics.
func StringToDialect(n string) qbs.Dialect {
	switch n {
	case "postgres":
		return qbs.NewPostgres()
	case "sqlite3":
		return qbs.NewSqlite3()
	}
	panic(fmt.Sprintf("unable to deal with db dialect provided %s", n))
}
Пример #4
0
func connDb() *qbs.Qbs {
	db := qbs.GetFreeDB()
	if db == nil {
		// 'sql.Open' only returns error when unknown driver, so it's not necessary to check in other places.
		db, _ = sql.Open(_SQLITE3_DRIVER, DB_NAME)
	}

	q := qbs.New(db, qbs.NewSqlite3())
	return q
}
Пример #5
0
func RegisterDb() {

	switch {
	case dbtypeset == "sqlite":
		qbs.Register("sqlite3", "./data/sqlite.db", "", qbs.NewSqlite3())

	case dbtypeset == "mysql":
		qbs.Register("mysql", "qbs_test@/qbs_test?charset=utf8&parseTime=true&loc=Local", "dbname", qbs.NewMysql())

	case dbtypeset == "pgsql":
		qbs.Register("postgres", "user=postgres password=jn!@#$%^&* dbname=pgsql sslmode=disable", "pgsql", qbs.NewPostgres())
	}

}
Пример #6
0
func SetMg() (mg *qbs.Migration, err error) {
	db, err := OpenDb(dbtypeset)

	switch {
	case dbtypeset == "sqlite":
		mg = qbs.NewMigration(db, DbName, qbs.NewSqlite3())
	case dbtypeset == "mysql":
		mg = qbs.NewMigration(db, DbName, qbs.NewMysql())
	case dbtypeset == "pgsql":
		mg = qbs.NewMigration(db, DbName, qbs.NewPostgres())

	}
	return mg, err
}
Пример #7
0
func RegisterDb() {

	switch {
	case dbtypeset == "sqlite":
		qbs.Register("sqlite3", "./data/sqlite.db", "", qbs.NewSqlite3())

	case dbtypeset == "mysql":
		qbs.Register("mysql", "qbs_test@/qbs_test?charset=utf8&parseTime=true&loc=Local", "dbname", qbs.NewMysql())

	case dbtypeset == "pgsql":
		qbs.Register("postgres", "qbs_test@/qbs_test?charset=utf8&parseTime=true&loc=Local", "dbname", qbs.NewPostgres())
	}

}
Пример #8
0
func init() {
	revel.OnAppStart(func() {
		var (
			found   bool
			spec    []string
			dialect qbs.Dialect
		)

		if Driver, found = revel.Config.String("db.driver"); !found {
			revel.ERROR.Fatal("No db.driver found.")
		}
		switch strings.ToLower(Driver) {
		case "mysql":
			dialect = qbs.NewMysql()
		case "postgres":
			dialect = qbs.NewPostgres()
		case "sqlite3":
			dialect = qbs.NewSqlite3()
		}

		// Start building the spec from available config options
		if User, found = revel.Config.String("db.user"); found {
			spec = append(spec, User)
			if Password, found = revel.Config.String("db.password"); found {
				spec = append(spec, fmt.Sprintf(":%v", Password))
			}
			spec = append(spec, "@")
		}
		if Protocol, found = revel.Config.String("db.protocol"); found {
			spec = append(spec, Protocol)
			if Address, found = revel.Config.String("db.address"); found {
				spec = append(spec, fmt.Sprintf("(%v)", Address))
			}
		}
		if DbName, found = revel.Config.String("db.dbname"); !found {
			revel.ERROR.Fatal("No db.dbname found.")
		}
		spec = append(spec, fmt.Sprintf("/%v", DbName))
		if Params, found = revel.Config.String("db.params"); found {
			spec = append(spec, fmt.Sprintf("?%v", Params))
		}

		qbs.Register(Driver, strings.Join(spec, ""), DbName, dialect)
		Db, err = qbs.GetQbs()
		defer Db.Close()
	})
}
Пример #9
0
func ConnDb() (q *qbs.Qbs, err error) {
	db := qbs.GetFreeDB()
	if db == nil {
		db, err = OpenDb(dbtypeset)
		if err != nil {
			return nil, err
		}
	}

	switch {
	case dbtypeset == "sqlite":
		q = qbs.New(db, qbs.NewSqlite3())

	case dbtypeset == "mysql":
		q = qbs.New(db, qbs.NewMysql())

	case dbtypeset == "pgsql":
		q = qbs.New(db, qbs.NewPostgres())

	}
	return q, nil
}
Пример #10
0
func init() {
	// Initialize database.
	os.Mkdir("./data", os.ModePerm)

	qbs.Register(_SQLITE3_DRIVER, DB_NAME, "", qbs.NewSqlite3())
	// Connect to database.
	q := connDb()
	defer q.Close()

	mg, err := setMg()
	if err != nil {
		beego.Error("models.init():", err)
	}
	defer mg.Close()

	// Create data tables.
	mg.CreateTableIfNotExists(new(PkgInfo))
	mg.CreateTableIfNotExists(new(PkgDecl))
	mg.CreateTableIfNotExists(new(PkgDoc))

	beego.Trace("Initialized database ->", DB_NAME)
}
Пример #11
0
func setMg() (*qbs.Migration, error) {
	db, err := sql.Open(_SQLITE3_DRIVER, DB_NAME)
	mg := qbs.NewMigration(db, DB_NAME, qbs.NewSqlite3())
	return mg, err
}
func init() {
	os.Remove("/tmp/tmp.db")
	qbs.Register("sqlite3", "/tmp/tmp.db", "", qbs.NewSqlite3())
}
Пример #13
0
func connDb() (*qbs.Qbs, error) {
	db, err := sql.Open(_SQLITE3_DRIVER, DB_NAME)
	q := qbs.New(db, qbs.NewSqlite3())
	return q, err
}
Пример #14
0
func SetMg() (*qbs.Migration, error) {
	db, err := sql.Open(sqlite3Driver, dbName)
	mg := qbs.NewMigration(db, dbName, qbs.NewSqlite3())
	return mg, err
}
Пример #15
0
func ConnDb() (*qbs.Qbs, error) {
	db, err := sql.Open(sqlite3Driver, dbName)
	q := qbs.New(db, qbs.NewSqlite3())
	return q, err
}