當前位置: 首頁>>代碼示例>>Golang>>正文


Golang LimitedTx.QueryRow方法代碼示例

本文整理匯總了Golang中github.com/BurntSushi/migration.LimitedTx.QueryRow方法的典型用法代碼示例。如果您正苦於以下問題:Golang LimitedTx.QueryRow方法的具體用法?Golang LimitedTx.QueryRow怎麽用?Golang LimitedTx.QueryRow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/BurntSushi/migration.LimitedTx的用法示例。


在下文中一共展示了LimitedTx.QueryRow方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: getVersion

// getVersion gets the migration version in the database.
func getVersion(tx migration.LimitedTx) (int, error) {
	var version int
	row := tx.QueryRow("SELECT version FROM migration_version")
	if err := row.Scan(&version); err != nil {
		return 0, err
	}
	return version, nil
}
開發者ID:Guoshusheng,項目名稱:drone-dart,代碼行數:9,代碼來源:version.go

示例2: get

func (d dbVersion) get(tx migration.LimitedTx) (int, error) {
	var version int
	r := tx.QueryRow(d.GetSQL)
	if err := r.Scan(&version); err != nil {
		return 0, err
	}
	return version, nil
}
開發者ID:ndlib,項目名稱:bendo,代碼行數:8,代碼來源:db.go

示例3: CreateEventIDSequencesForInFlightBuilds

func CreateEventIDSequencesForInFlightBuilds(tx migration.LimitedTx) error {
	cursor := 0

	for {
		var id, eventIDStart int

		err := tx.QueryRow(`
      SELECT id, max(event_id)
      FROM builds
      LEFT JOIN build_events
      ON build_id = id
      WHERE id > $1
      AND status = 'started'
      GROUP BY id
      ORDER BY id ASC
      LIMIT 1
    `, cursor).Scan(&id, &eventIDStart)
		if err != nil {
			if err == sql.ErrNoRows {
				break
			}

			return err
		}

		cursor = id

		_, err = tx.Exec(fmt.Sprintf(`
      CREATE SEQUENCE %s MINVALUE 0 START WITH %d
    `, buildEventSeq(id), eventIDStart+1))
		if err != nil {
			return err
		}
	}

	return nil
}
開發者ID:utako,項目名稱:atc,代碼行數:37,代碼來源:21_create_event_id_sequences_for_in_flight_builds.go

示例4: AddBuildEvents

func AddBuildEvents(tx migration.LimitedTx) error {
	_, err := tx.Exec(`
    CREATE TABLE build_events (
      id serial PRIMARY KEY,
      build_id integer REFERENCES builds (id),
			type varchar(32) NOT NULL,
      payload text NOT NULL
    )
  `)
	if err != nil {
		return err
	}

	cursor := 0

	for {
		var id int
		var buildLog sql.NullString

		err := tx.QueryRow(`
			SELECT id, log
			FROM builds
			WHERE id > $1
			ORDER BY id ASC
			LIMIT 1
		`, cursor).Scan(&id, &buildLog)
		if err != nil {
			if err == sql.ErrNoRows {
				break
			}

			return err
		}

		cursor = id

		if !buildLog.Valid {
			continue
		}

		logBuf := bytes.NewBufferString(buildLog.String)
		decoder := json.NewDecoder(logBuf)

		for {
			var entry logEntry

			err := decoder.Decode(&entry)
			if err != nil {
				if err != io.EOF {
					// non-JSON log; assume v0.0

					_, err = tx.Exec(`
						INSERT INTO build_events (build_id, type, payload)
						VALUES ($1, $2, $3)
					`, id, "version", "0.0")
					if err != nil {
						return err
					}

					_, err = tx.Exec(`
							INSERT INTO build_events (build_id, type, payload)
							VALUES ($1, $2, $3)
						`, id, "log", buildLog.String)
					if err != nil {
						return err
					}
				}

				break
			}

			if entry.Type != "" && entry.EventPayload != nil {
				_, err = tx.Exec(`
						INSERT INTO build_events (build_id, type, payload)
						VALUES ($1, $2, $3)
					`, id, entry.Type, []byte(*entry.EventPayload))
				if err != nil {
					return err
				}

				continue
			}

			if entry.Version != "" {
				versionEnc, err := json.Marshal(entry.Version)
				if err != nil {
					return err
				}

				_, err = tx.Exec(`
					INSERT INTO build_events (build_id, type, payload)
					VALUES ($1, $2, $3)
				`, id, "version", versionEnc)
				if err != nil {
					return err
				}

				continue
			}

//.........這裏部分代碼省略.........
開發者ID:utako,項目名稱:atc,代碼行數:101,代碼來源:10_add_build_events.go

示例5: AddEngineAndEngineMetadataToBuilds

func AddEngineAndEngineMetadataToBuilds(tx migration.LimitedTx) error {
	_, err := tx.Exec(`ALTER TABLE builds ADD COLUMN engine varchar(16)`)
	if err != nil {
		return err
	}

	_, err = tx.Exec(`ALTER TABLE builds ADD COLUMN engine_metadata text`)
	if err != nil {
		return err
	}

	cursor := 0

	for {
		var id int
		var guid, endpoint string

		err := tx.QueryRow(`
      SELECT id, guid, endpoint
      FROM builds
      WHERE id > $1
      AND guid != ''
      ORDER BY id ASC
      LIMIT 1
    `, cursor).Scan(&id, &guid, &endpoint)
		if err != nil {
			if err == sql.ErrNoRows {
				break
			}

			return err
		}

		cursor = id

		engineMetadata := turbineMetadata{
			Guid:     guid,
			Endpoint: endpoint,
		}

		payload, err := json.Marshal(engineMetadata)
		if err != nil {
			continue
		}

		_, err = tx.Exec(`
      UPDATE builds
      SET engine = $1, engine_metadata = $2
      WHERE id = $3
    `, "turbine", payload, id)
		if err != nil {
			continue
		}
	}

	_, err = tx.Exec(`ALTER TABLE builds DROP COLUMN guid`)
	if err != nil {
		return err
	}

	_, err = tx.Exec(`ALTER TABLE builds DROP COLUMN endpoint`)
	if err != nil {
		return err
	}

	return nil
}
開發者ID:utako,項目名稱:atc,代碼行數:67,代碼來源:17_add_engine_and_engine_metadata_to_builds.go

示例6: ReplaceBuildsAbortHijackURLsWithGuidAndEndpoint

func ReplaceBuildsAbortHijackURLsWithGuidAndEndpoint(tx migration.LimitedTx) error {
	_, err := tx.Exec(`ALTER TABLE builds ADD COLUMN guid varchar(36)`)
	if err != nil {
		return err
	}

	_, err = tx.Exec(`ALTER TABLE builds ADD COLUMN endpoint varchar(128)`)
	if err != nil {
		return err
	}

	cursor := 0

	for {
		var id int
		var abortURLStr sql.NullString

		err := tx.QueryRow(`
			SELECT id, abort_url
			FROM builds
			WHERE id > $1
			LIMIT 1
		`, cursor).Scan(&id, &abortURLStr)
		if err != nil {
			if err == sql.ErrNoRows {
				break
			}

			return err
		}

		cursor = id

		if !abortURLStr.Valid {
			continue
		}

		// determine guid + endpoint from abort url
		//
		// format should be http://foo.com:5050/builds/some-guid/abort
		//
		// best-effort; skip if not possible, not a big deal

		abortURL, err := url.Parse(abortURLStr.String)
		if err != nil {
			continue
		}

		pathSegments := strings.Split(abortURL.Path, "/")
		if len(pathSegments) != 4 {
			continue
		}

		guid := pathSegments[2]
		endpoint := abortURL.Scheme + "://" + abortURL.Host

		_, err = tx.Exec(`
			UPDATE builds
			SET guid = $1, endpoint = $2
			WHERE id = $3
		`, guid, endpoint, id)
		if err != nil {
			continue
		}
	}

	_, err = tx.Exec(`ALTER TABLE builds DROP COLUMN abort_url`)
	if err != nil {
		return err
	}

	_, err = tx.Exec(`ALTER TABLE builds DROP COLUMN hijack_url`)
	if err != nil {
		return err
	}

	return nil
}
開發者ID:utako,項目名稱:atc,代碼行數:78,代碼來源:11_replace_builds_abort_hijack_urls_with_guid_and_endpoint.go


注:本文中的github.com/BurntSushi/migration.LimitedTx.QueryRow方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。