예제 #1
0
func UpdateIPTypes(db Queryer,
	id int32,
	row *IPTypes,
) error {
	sets := make([]string, 0, 3)
	args := pgx.QueryArgs(make([]interface{}, 0, 3))

	row.ID.addUpdate(`id`, &sets, &args)
	row.IPInet.addUpdate(`ip_inet`, &sets, &args)
	row.IPCidr.addUpdate(`ip_cidr`, &sets, &args)

	if len(sets) == 0 {
		return nil
	}

	sql := `update "ip_types" set ` + strings.Join(sets, ", ") + ` where ` + `"id"=` + args.Append(id)

	psName := preparedName("pgxdataUpdateIPTypes", sql)

	commandTag, err := prepareExec(db, psName, sql, args...)
	if err != nil {
		return err
	}
	if commandTag.RowsAffected() != 1 {
		return ErrNotFound
	}
	return nil
}
예제 #2
0
파일: pgxdata_feed.go 프로젝트: jackc/tpr
func UpdateFeed(db Queryer,
	id int32,
	row *Feed,
) error {
	sets := make([]string, 0, 9)
	args := pgx.QueryArgs(make([]interface{}, 0, 9))

	row.ID.addUpdate(`id`, &sets, &args)
	row.Name.addUpdate(`name`, &sets, &args)
	row.URL.addUpdate(`url`, &sets, &args)
	row.LastFetchTime.addUpdate(`last_fetch_time`, &sets, &args)
	row.ETag.addUpdate(`etag`, &sets, &args)
	row.LastFailure.addUpdate(`last_failure`, &sets, &args)
	row.LastFailureTime.addUpdate(`last_failure_time`, &sets, &args)
	row.FailureCount.addUpdate(`failure_count`, &sets, &args)
	row.CreationTime.addUpdate(`creation_time`, &sets, &args)

	if len(sets) == 0 {
		return nil
	}

	sql := `update "feeds" set ` + strings.Join(sets, ", ") + ` where ` + `"id"=` + args.Append(id)

	psName := preparedName("pgxdataUpdateFeed", sql)

	commandTag, err := prepareExec(db, psName, sql, args...)
	if err != nil {
		return err
	}
	if commandTag.RowsAffected() != 1 {
		return ErrNotFound
	}
	return nil
}
예제 #3
0
파일: widget.go 프로젝트: sguzwf/pgxdata
func UpdateWidget(db Queryer,
	id int64,
	row *Widget,
) error {
	sets := make([]string, 0, 3)
	args := pgx.QueryArgs(make([]interface{}, 0, 3))

	row.ID.addUpdate(`id`, &sets, &args)
	row.Name.addUpdate(`name`, &sets, &args)
	row.Weight.addUpdate(`weight`, &sets, &args)

	if len(sets) == 0 {
		return nil
	}

	sql := `update "widget" set ` + strings.Join(sets, ", ") + ` where ` + `"id"=` + args.Append(id)

	commandTag, err := db.Exec(sql, args...)
	if err != nil {
		return err
	}
	if commandTag.RowsAffected() != 1 {
		return pgx.ErrNoRows
	}
	return nil
}
func UpdateRenamedFieldCustomer(db Queryer,
	id int32,
	row *RenamedFieldCustomer,
) error {
	sets := make([]string, 0, 5)
	args := pgx.QueryArgs(make([]interface{}, 0, 5))

	row.ID.addUpdate(`id`, &sets, &args)
	row.FName.addUpdate(`first_name`, &sets, &args)
	row.LastName.addUpdate(`last_name`, &sets, &args)
	row.BirthDate.addUpdate(`birth_date`, &sets, &args)
	row.CreationTime.addUpdate(`creation_time`, &sets, &args)

	if len(sets) == 0 {
		return nil
	}

	sql := `update "customer" set ` + strings.Join(sets, ", ") + ` where ` + `"id"=` + args.Append(id)

	psName := preparedName("pgxdataUpdateRenamedFieldCustomer", sql)

	commandTag, err := prepareExec(db, psName, sql, args...)
	if err != nil {
		return err
	}
	if commandTag.RowsAffected() != 1 {
		return ErrNotFound
	}
	return nil
}
예제 #5
0
func UpdateBlob(db Queryer,
	id int32,
	row *Blob,
) error {
	sets := make([]string, 0, 2)
	args := pgx.QueryArgs(make([]interface{}, 0, 2))

	row.ID.addUpdate(`id`, &sets, &args)
	row.Payload.addUpdate(`payload`, &sets, &args)

	if len(sets) == 0 {
		return nil
	}

	sql := `update "blob" set ` + strings.Join(sets, ", ") + ` where ` + `"id"=` + args.Append(id)

	psName := preparedName("pgxdataUpdateBlob", sql)

	commandTag, err := prepareExec(db, psName, sql, args...)
	if err != nil {
		return err
	}
	if commandTag.RowsAffected() != 1 {
		return ErrNotFound
	}
	return nil
}
예제 #6
0
func UpdateSession(db Queryer,
	id []byte,
	row *Session,
) error {
	sets := make([]string, 0, 3)
	args := pgx.QueryArgs(make([]interface{}, 0, 3))

	row.ID.addUpdate(`id`, &sets, &args)
	row.UserID.addUpdate(`user_id`, &sets, &args)
	row.StartTime.addUpdate(`start_time`, &sets, &args)

	if len(sets) == 0 {
		return nil
	}

	sql := `update "sessions" set ` + strings.Join(sets, ", ") + ` where ` + `"id"=` + args.Append(id)

	psName := preparedName("pgxdataUpdateSession", sql)

	commandTag, err := prepareExec(db, psName, sql, args...)
	if err != nil {
		return err
	}
	if commandTag.RowsAffected() != 1 {
		return ErrNotFound
	}
	return nil
}
예제 #7
0
func UpdatePasswordReset(db Queryer,
	token string,
	row *PasswordReset,
) error {
	sets := make([]string, 0, 7)
	args := pgx.QueryArgs(make([]interface{}, 0, 7))

	row.Token.addUpdate(`token`, &sets, &args)
	row.Email.addUpdate(`email`, &sets, &args)
	row.RequestIP.addUpdate(`request_ip`, &sets, &args)
	row.RequestTime.addUpdate(`request_time`, &sets, &args)
	row.UserID.addUpdate(`user_id`, &sets, &args)
	row.CompletionIP.addUpdate(`completion_ip`, &sets, &args)
	row.CompletionTime.addUpdate(`completion_time`, &sets, &args)

	if len(sets) == 0 {
		return nil
	}

	sql := `update "password_resets" set ` + strings.Join(sets, ", ") + ` where ` + `"token"=` + args.Append(token)

	psName := preparedName("pgxdataUpdatePasswordReset", sql)

	commandTag, err := prepareExec(db, psName, sql, args...)
	if err != nil {
		return err
	}
	if commandTag.RowsAffected() != 1 {
		return ErrNotFound
	}
	return nil
}
예제 #8
0
파일: semester.go 프로젝트: sguzwf/pgxdata
func UpdateSemester(db Queryer,
	year int16,
	season string,
	row *Semester,
) error {
	sets := make([]string, 0, 3)
	args := pgx.QueryArgs(make([]interface{}, 0, 3))

	row.Year.addUpdate(`year`, &sets, &args)
	row.Season.addUpdate(`season`, &sets, &args)
	row.Description.addUpdate(`description`, &sets, &args)

	if len(sets) == 0 {
		return nil
	}

	sql := `update "semester" set ` + strings.Join(sets, ", ") + ` where ` + `"year"=` + args.Append(year) + ` and "season"=` + args.Append(season)

	commandTag, err := db.Exec(sql, args...)
	if err != nil {
		return err
	}
	if commandTag.RowsAffected() != 1 {
		return pgx.ErrNoRows
	}
	return nil
}
예제 #9
0
파일: part.go 프로젝트: sguzwf/pgxdata
func UpdatePart(db Queryer,
	code string,
	row *Part,
) error {
	sets := make([]string, 0, 2)
	args := pgx.QueryArgs(make([]interface{}, 0, 2))

	row.Code.addUpdate(`code`, &sets, &args)
	row.Description.addUpdate(`description`, &sets, &args)

	if len(sets) == 0 {
		return nil
	}

	sql := `update "part" set ` + strings.Join(sets, ", ") + ` where ` + `"code"=` + args.Append(code)

	commandTag, err := db.Exec(sql, args...)
	if err != nil {
		return err
	}
	if commandTag.RowsAffected() != 1 {
		return pgx.ErrNoRows
	}
	return nil
}
예제 #10
0
파일: customer.go 프로젝트: sguzwf/pgxdata
func UpdateCustomer(db Queryer,
	id int32,
	row *Customer,
) error {
	sets := make([]string, 0, 5)
	args := pgx.QueryArgs(make([]interface{}, 0, 5))

	row.ID.addUpdate(`id`, &sets, &args)
	row.FirstName.addUpdate(`first_name`, &sets, &args)
	row.LastName.addUpdate(`last_name`, &sets, &args)
	row.BirthDate.addUpdate(`birth_date`, &sets, &args)
	row.CreationTime.addUpdate(`creation_time`, &sets, &args)

	if len(sets) == 0 {
		return nil
	}

	sql := `update "customer" set ` + strings.Join(sets, ", ") + ` where ` + `"id"=` + args.Append(id)

	commandTag, err := db.Exec(sql, args...)
	if err != nil {
		return err
	}
	if commandTag.RowsAffected() != 1 {
		return pgx.ErrNoRows
	}
	return nil
}
예제 #11
0
파일: pgxdata_user.go 프로젝트: jackc/tpr
func UpdateUser(db Queryer,
	id int32,
	row *User,
) error {
	sets := make([]string, 0, 5)
	args := pgx.QueryArgs(make([]interface{}, 0, 5))

	row.ID.addUpdate(`id`, &sets, &args)
	row.Name.addUpdate(`name`, &sets, &args)
	row.PasswordDigest.addUpdate(`password_digest`, &sets, &args)
	row.PasswordSalt.addUpdate(`password_salt`, &sets, &args)
	row.Email.addUpdate(`email`, &sets, &args)

	if len(sets) == 0 {
		return nil
	}

	sql := `update "users" set ` + strings.Join(sets, ", ") + ` where ` + `"id"=` + args.Append(id)

	psName := preparedName("pgxdataUpdateUser", sql)

	commandTag, err := prepareExec(db, psName, sql, args...)
	if err != nil {
		return err
	}
	if commandTag.RowsAffected() != 1 {
		return ErrNotFound
	}
	return nil
}
예제 #12
0
파일: sql_test.go 프로젝트: segmentio/pgx
func BenchmarkQueryArgs(b *testing.B) {
	for i := 0; i < b.N; i++ {
		qa := pgx.QueryArgs(make([]interface{}, 0, 16))
		qa.Append("foo1")
		qa.Append("foo2")
		qa.Append("foo3")
		qa.Append("foo4")
		qa.Append("foo5")
		qa.Append("foo6")
		qa.Append("foo7")
		qa.Append("foo8")
		qa.Append("foo9")
		qa.Append("foo10")
	}
}
예제 #13
0
파일: part.go 프로젝트: sguzwf/pgxdata
func InsertPart(db Queryer, row *Part) error {
	args := pgx.QueryArgs(make([]interface{}, 0, 2))

	var columns, values []string

	row.Code.addInsert(`code`, &columns, &values, &args)
	row.Description.addInsert(`description`, &columns, &values, &args)

	sql := `insert into "part"(` + strings.Join(columns, ", ") + `)
values(` + strings.Join(values, ",") + `)
returning "code"
  `

	return db.QueryRow(sql, args...).Scan(&row.Code)
}
예제 #14
0
func DeletePasswordReset(db Queryer,
	token string,
) error {
	args := pgx.QueryArgs(make([]interface{}, 0, 1))

	sql := `delete from "password_resets" where ` + `"token"=` + args.Append(token)

	commandTag, err := prepareExec(db, "pgxdataDeletePasswordReset", sql, args...)
	if err != nil {
		return err
	}
	if commandTag.RowsAffected() != 1 {
		return ErrNotFound
	}
	return nil
}
예제 #15
0
func DeleteBlob(db Queryer,
	id int32,
) error {
	args := pgx.QueryArgs(make([]interface{}, 0, 1))

	sql := `delete from "blob" where ` + `"id"=` + args.Append(id)

	commandTag, err := prepareExec(db, "pgxdataDeleteBlob", sql, args...)
	if err != nil {
		return err
	}
	if commandTag.RowsAffected() != 1 {
		return ErrNotFound
	}
	return nil
}
예제 #16
0
파일: widget.go 프로젝트: sguzwf/pgxdata
func InsertWidget(db Queryer, row *Widget) error {
	args := pgx.QueryArgs(make([]interface{}, 0, 3))

	var columns, values []string

	row.ID.addInsert(`id`, &columns, &values, &args)
	row.Name.addInsert(`name`, &columns, &values, &args)
	row.Weight.addInsert(`weight`, &columns, &values, &args)

	sql := `insert into "widget"(` + strings.Join(columns, ", ") + `)
values(` + strings.Join(values, ",") + `)
returning "id"
  `

	return db.QueryRow(sql, args...).Scan(&row.ID)
}
예제 #17
0
파일: part.go 프로젝트: sguzwf/pgxdata
func DeletePart(db Queryer,
	code string,
) error {
	args := pgx.QueryArgs(make([]interface{}, 0, 1))

	sql := `delete from "part" where ` + `"code"=` + args.Append(code)

	commandTag, err := db.Exec(sql, args...)
	if err != nil {
		return err
	}
	if commandTag.RowsAffected() != 1 {
		return pgx.ErrNoRows
	}
	return nil
}
예제 #18
0
파일: widget.go 프로젝트: sguzwf/pgxdata
func DeleteWidget(db Queryer,
	id int64,
) error {
	args := pgx.QueryArgs(make([]interface{}, 0, 1))

	sql := `delete from "widget" where ` + `"id"=` + args.Append(id)

	commandTag, err := db.Exec(sql, args...)
	if err != nil {
		return err
	}
	if commandTag.RowsAffected() != 1 {
		return pgx.ErrNoRows
	}
	return nil
}
예제 #19
0
파일: semester.go 프로젝트: sguzwf/pgxdata
func InsertSemester(db Queryer, row *Semester) error {
	args := pgx.QueryArgs(make([]interface{}, 0, 3))

	var columns, values []string

	row.Year.addInsert(`year`, &columns, &values, &args)
	row.Season.addInsert(`season`, &columns, &values, &args)
	row.Description.addInsert(`description`, &columns, &values, &args)

	sql := `insert into "semester"(` + strings.Join(columns, ", ") + `)
values(` + strings.Join(values, ",") + `)
returning "year", "season"
  `

	return db.QueryRow(sql, args...).Scan(&row.Year, &row.Season)
}
예제 #20
0
파일: semester.go 프로젝트: sguzwf/pgxdata
func DeleteSemester(db Queryer,
	year int16,
	season string,
) error {
	args := pgx.QueryArgs(make([]interface{}, 0, 2))

	sql := `delete from "semester" where ` + `"year"=` + args.Append(year) + ` and "season"=` + args.Append(season)

	commandTag, err := db.Exec(sql, args...)
	if err != nil {
		return err
	}
	if commandTag.RowsAffected() != 1 {
		return pgx.ErrNoRows
	}
	return nil
}
예제 #21
0
func InsertBlob(db Queryer, row *Blob) error {
	args := pgx.QueryArgs(make([]interface{}, 0, 2))

	var columns, values []string

	row.ID.addInsert(`id`, &columns, &values, &args)
	row.Payload.addInsert(`payload`, &columns, &values, &args)

	sql := `insert into "blob"(` + strings.Join(columns, ", ") + `)
values(` + strings.Join(values, ",") + `)
returning "id"
  `

	psName := preparedName("pgxdataInsertBlob", sql)

	return prepareQueryRow(db, psName, sql, args...).Scan(&row.ID)
}
예제 #22
0
func InsertIPTypes(db Queryer, row *IPTypes) error {
	args := pgx.QueryArgs(make([]interface{}, 0, 3))

	var columns, values []string

	row.ID.addInsert(`id`, &columns, &values, &args)
	row.IPInet.addInsert(`ip_inet`, &columns, &values, &args)
	row.IPCidr.addInsert(`ip_cidr`, &columns, &values, &args)

	sql := `insert into "ip_types"(` + strings.Join(columns, ", ") + `)
values(` + strings.Join(values, ",") + `)
returning "id"
  `

	psName := preparedName("pgxdataInsertIPTypes", sql)

	return prepareQueryRow(db, psName, sql, args...).Scan(&row.ID)
}
예제 #23
0
func InsertRenamedFieldCustomer(db Queryer, row *RenamedFieldCustomer) error {
	args := pgx.QueryArgs(make([]interface{}, 0, 5))

	var columns, values []string

	row.ID.addInsert(`id`, &columns, &values, &args)
	row.FName.addInsert(`first_name`, &columns, &values, &args)
	row.LastName.addInsert(`last_name`, &columns, &values, &args)
	row.BirthDate.addInsert(`birth_date`, &columns, &values, &args)
	row.CreationTime.addInsert(`creation_time`, &columns, &values, &args)

	sql := `insert into "customer"(` + strings.Join(columns, ", ") + `)
values(` + strings.Join(values, ",") + `)
returning "id"
  `

	return db.QueryRow(sql, args...).Scan(&row.ID)
}
예제 #24
0
func InsertSession(db Queryer, row *Session) error {
	args := pgx.QueryArgs(make([]interface{}, 0, 3))

	var columns, values []string

	row.ID.addInsert(`id`, &columns, &values, &args)
	row.UserID.addInsert(`user_id`, &columns, &values, &args)
	row.StartTime.addInsert(`start_time`, &columns, &values, &args)

	sql := `insert into "sessions"(` + strings.Join(columns, ", ") + `)
values(` + strings.Join(values, ",") + `)
returning "id"
  `

	psName := preparedName("pgxdataInsertSession", sql)

	return prepareQueryRow(db, psName, sql, args...).Scan(&row.ID)
}
예제 #25
0
func InsertCustomer(db Queryer, row *Customer) error {
	args := pgx.QueryArgs(make([]interface{}, 0, 5))

	var columns, values []string

	row.ID.addInsert(`id`, &columns, &values, &args)
	row.FirstName.addInsert(`first_name`, &columns, &values, &args)
	row.LastName.addInsert(`last_name`, &columns, &values, &args)
	row.BirthDate.addInsert(`birth_date`, &columns, &values, &args)
	row.CreationTime.addInsert(`creation_time`, &columns, &values, &args)

	sql := `insert into "customer"(` + strings.Join(columns, ", ") + `)
values(` + strings.Join(values, ",") + `)
returning "id"
  `

	psName := preparedName("pgxdataInsertCustomer", sql)

	return prepareQueryRow(db, psName, sql, args...).Scan(&row.ID)
}
예제 #26
0
파일: pgxdata_user.go 프로젝트: jackc/tpr
func InsertUser(db Queryer, row *User) error {
	args := pgx.QueryArgs(make([]interface{}, 0, 5))

	var columns, values []string

	row.ID.addInsert(`id`, &columns, &values, &args)
	row.Name.addInsert(`name`, &columns, &values, &args)
	row.PasswordDigest.addInsert(`password_digest`, &columns, &values, &args)
	row.PasswordSalt.addInsert(`password_salt`, &columns, &values, &args)
	row.Email.addInsert(`email`, &columns, &values, &args)

	sql := `insert into "users"(` + strings.Join(columns, ", ") + `)
values(` + strings.Join(values, ",") + `)
returning "id"
  `

	psName := preparedName("pgxdataInsertUser", sql)

	return prepareQueryRow(db, psName, sql, args...).Scan(&row.ID)
}
예제 #27
0
func InsertPasswordReset(db Queryer, row *PasswordReset) error {
	args := pgx.QueryArgs(make([]interface{}, 0, 7))

	var columns, values []string

	row.Token.addInsert(`token`, &columns, &values, &args)
	row.Email.addInsert(`email`, &columns, &values, &args)
	row.RequestIP.addInsert(`request_ip`, &columns, &values, &args)
	row.RequestTime.addInsert(`request_time`, &columns, &values, &args)
	row.UserID.addInsert(`user_id`, &columns, &values, &args)
	row.CompletionIP.addInsert(`completion_ip`, &columns, &values, &args)
	row.CompletionTime.addInsert(`completion_time`, &columns, &values, &args)

	sql := `insert into "password_resets"(` + strings.Join(columns, ", ") + `)
values(` + strings.Join(values, ",") + `)
returning "token"
  `

	psName := preparedName("pgxdataInsertPasswordReset", sql)

	return prepareQueryRow(db, psName, sql, args...).Scan(&row.Token)
}
예제 #28
0
파일: pgxdata_feed.go 프로젝트: jackc/tpr
func InsertFeed(db Queryer, row *Feed) error {
	args := pgx.QueryArgs(make([]interface{}, 0, 9))

	var columns, values []string

	row.ID.addInsert(`id`, &columns, &values, &args)
	row.Name.addInsert(`name`, &columns, &values, &args)
	row.URL.addInsert(`url`, &columns, &values, &args)
	row.LastFetchTime.addInsert(`last_fetch_time`, &columns, &values, &args)
	row.ETag.addInsert(`etag`, &columns, &values, &args)
	row.LastFailure.addInsert(`last_failure`, &columns, &values, &args)
	row.LastFailureTime.addInsert(`last_failure_time`, &columns, &values, &args)
	row.FailureCount.addInsert(`failure_count`, &columns, &values, &args)
	row.CreationTime.addInsert(`creation_time`, &columns, &values, &args)

	sql := `insert into "feeds"(` + strings.Join(columns, ", ") + `)
values(` + strings.Join(values, ",") + `)
returning "id"
  `

	psName := preparedName("pgxdataInsertFeed", sql)

	return prepareQueryRow(db, psName, sql, args...).Scan(&row.ID)
}