sql updates
This commit is contained in:
@@ -78,13 +78,135 @@ func (q *Queries) CreateInventory(ctx context.Context, arg CreateInventoryParams
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getInventoryByName = `-- name: GetInventoryByName :one
|
||||
SELECT Iid, Name, Vcenter, VmId, EventKey, EventId, CreationTime, DeletionTime, ResourcePool, VmType, Datacenter, Cluster, Folder, ProvisionedDisk, InitialVcpus, InitialRam, SrmPlaceholder FROM "Inventory"
|
||||
WHERE "Name" = ? LIMIT 1
|
||||
const createUpdate = `-- name: CreateUpdate :one
|
||||
INSERT INTO "Updates" (
|
||||
"InventoryId", "EventKey", "EventId", "UpdateTime", "UpdateType", "NewVcpus", "NewRam", "NewResourcePool"
|
||||
) VALUES(
|
||||
?, ?, ?, ?, ?, ?, ?, ?
|
||||
)
|
||||
RETURNING Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId
|
||||
`
|
||||
|
||||
func (q *Queries) GetInventoryByName(ctx context.Context, name string) (Inventory, error) {
|
||||
row := q.db.QueryRowContext(ctx, getInventoryByName, name)
|
||||
type CreateUpdateParams struct {
|
||||
InventoryId sql.NullInt64
|
||||
EventKey sql.NullString
|
||||
EventId sql.NullString
|
||||
UpdateTime sql.NullInt64
|
||||
UpdateType string
|
||||
NewVcpus sql.NullInt64
|
||||
NewRam sql.NullInt64
|
||||
NewResourcePool sql.NullString
|
||||
}
|
||||
|
||||
func (q *Queries) CreateUpdate(ctx context.Context, arg CreateUpdateParams) (Updates, error) {
|
||||
row := q.db.QueryRowContext(ctx, createUpdate,
|
||||
arg.InventoryId,
|
||||
arg.EventKey,
|
||||
arg.EventId,
|
||||
arg.UpdateTime,
|
||||
arg.UpdateType,
|
||||
arg.NewVcpus,
|
||||
arg.NewRam,
|
||||
arg.NewResourcePool,
|
||||
)
|
||||
var i Updates
|
||||
err := row.Scan(
|
||||
&i.Uid,
|
||||
&i.InventoryId,
|
||||
&i.UpdateTime,
|
||||
&i.UpdateType,
|
||||
&i.NewVcpus,
|
||||
&i.NewRam,
|
||||
&i.NewResourcePool,
|
||||
&i.EventKey,
|
||||
&i.EventId,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getInventoryByName = `-- name: GetInventoryByName :many
|
||||
SELECT Iid, Name, Vcenter, VmId, EventKey, EventId, CreationTime, DeletionTime, ResourcePool, VmType, Datacenter, Cluster, Folder, ProvisionedDisk, InitialVcpus, InitialRam, SrmPlaceholder FROM "Inventory"
|
||||
WHERE "Name" = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetInventoryByName(ctx context.Context, name string) ([]Inventory, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getInventoryByName, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Inventory
|
||||
for rows.Next() {
|
||||
var i Inventory
|
||||
if err := rows.Scan(
|
||||
&i.Iid,
|
||||
&i.Name,
|
||||
&i.Vcenter,
|
||||
&i.VmId,
|
||||
&i.EventKey,
|
||||
&i.EventId,
|
||||
&i.CreationTime,
|
||||
&i.DeletionTime,
|
||||
&i.ResourcePool,
|
||||
&i.VmType,
|
||||
&i.Datacenter,
|
||||
&i.Cluster,
|
||||
&i.Folder,
|
||||
&i.ProvisionedDisk,
|
||||
&i.InitialVcpus,
|
||||
&i.InitialRam,
|
||||
&i.SrmPlaceholder,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getInventoryEventId = `-- name: GetInventoryEventId :one
|
||||
SELECT Iid, Name, Vcenter, VmId, EventKey, EventId, CreationTime, DeletionTime, ResourcePool, VmType, Datacenter, Cluster, Folder, ProvisionedDisk, InitialVcpus, InitialRam, SrmPlaceholder FROM "Inventory"
|
||||
WHERE "EventId" = ? LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) GetInventoryEventId(ctx context.Context, eventid sql.NullString) (Inventory, error) {
|
||||
row := q.db.QueryRowContext(ctx, getInventoryEventId, eventid)
|
||||
var i Inventory
|
||||
err := row.Scan(
|
||||
&i.Iid,
|
||||
&i.Name,
|
||||
&i.Vcenter,
|
||||
&i.VmId,
|
||||
&i.EventKey,
|
||||
&i.EventId,
|
||||
&i.CreationTime,
|
||||
&i.DeletionTime,
|
||||
&i.ResourcePool,
|
||||
&i.VmType,
|
||||
&i.Datacenter,
|
||||
&i.Cluster,
|
||||
&i.Folder,
|
||||
&i.ProvisionedDisk,
|
||||
&i.InitialVcpus,
|
||||
&i.InitialRam,
|
||||
&i.SrmPlaceholder,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getInventoryVmId = `-- name: GetInventoryVmId :one
|
||||
SELECT Iid, Name, Vcenter, VmId, EventKey, EventId, CreationTime, DeletionTime, ResourcePool, VmType, Datacenter, Cluster, Folder, ProvisionedDisk, InitialVcpus, InitialRam, SrmPlaceholder FROM "Inventory"
|
||||
WHERE "VmId" = ? LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) GetInventoryVmId(ctx context.Context, vmid sql.NullString) (Inventory, error) {
|
||||
row := q.db.QueryRowContext(ctx, getInventoryVmId, vmid)
|
||||
var i Inventory
|
||||
err := row.Scan(
|
||||
&i.Iid,
|
||||
|
Reference in New Issue
Block a user