work on optimising vcenter queries
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-01-14 17:00:40 +11:00
parent 44ae2094f3
commit 56f021590d
8 changed files with 419 additions and 193 deletions

View File

@@ -59,6 +59,15 @@ type InventoryHistory struct {
PreviousProvisionedDisk sql.NullFloat64 `db:"PreviousProvisionedDisk" json:"PreviousProvisionedDisk"`
}
type PragmaTableInfo struct {
Cid sql.NullInt64 `db:"cid" json:"cid"`
Name sql.NullString `db:"name" json:"name"`
Type sql.NullString `db:"type" json:"type"`
Notnull sql.NullInt64 `db:"notnull" json:"notnull"`
DfltValue sql.NullString `db:"dflt_value" json:"dflt_value"`
Pk sql.NullInt64 `db:"pk" json:"pk"`
}
type SnapshotRegistry struct {
ID int64 `db:"id" json:"id"`
SnapshotType string `db:"snapshot_type" json:"snapshot_type"`
@@ -66,6 +75,14 @@ type SnapshotRegistry struct {
SnapshotTime int64 `db:"snapshot_time" json:"snapshot_time"`
}
type SqliteMaster struct {
Type sql.NullString `db:"type" json:"type"`
Name sql.NullString `db:"name" json:"name"`
TblName sql.NullString `db:"tbl_name" json:"tbl_name"`
Rootpage sql.NullInt64 `db:"rootpage" json:"rootpage"`
Sql sql.NullString `db:"sql" json:"sql"`
}
type Update struct {
Uid int64 `db:"Uid" json:"Uid"`
InventoryId sql.NullInt64 `db:"InventoryId" json:"InventoryId"`

View File

@@ -119,3 +119,13 @@ INSERT INTO inventory_history (
?, ?, ?, ?, ?, ?, ?
)
RETURNING *;
-- name: SqliteTableExists :one
SELECT COUNT(1) AS count
FROM sqlite_master
WHERE type = 'table' AND name = sqlc.arg('table_name');
-- name: SqliteColumnExists :one
SELECT COUNT(1) AS count
FROM pragma_table_info
WHERE name = sqlc.arg('column_name');

View File

@@ -876,6 +876,32 @@ func (q *Queries) ListUnprocessedEvents(ctx context.Context, eventtime sql.NullI
return items, nil
}
const sqliteColumnExists = `-- name: SqliteColumnExists :one
SELECT COUNT(1) AS count
FROM pragma_table_info
WHERE name = ?1
`
func (q *Queries) SqliteColumnExists(ctx context.Context, columnName sql.NullString) (int64, error) {
row := q.db.QueryRowContext(ctx, sqliteColumnExists, columnName)
var count int64
err := row.Scan(&count)
return count, err
}
const sqliteTableExists = `-- name: SqliteTableExists :one
SELECT COUNT(1) AS count
FROM sqlite_master
WHERE type = 'table' AND name = ?1
`
func (q *Queries) SqliteTableExists(ctx context.Context, tableName sql.NullString) (int64, error) {
row := q.db.QueryRowContext(ctx, sqliteTableExists, tableName)
var count int64
err := row.Scan(&count)
return count, err
}
const updateEventsProcessed = `-- name: UpdateEventsProcessed :exec
UPDATE events
SET "Processed" = 1