github.com/navikt/knorten@v0.0.0-20240419132333-1333f46ed8b6/pkg/database/gensql/global_values.sql.go (about)

     1  // Code generated by sqlc. DO NOT EDIT.
     2  // source: global_values.sql
     3  
     4  package gensql
     5  
     6  import (
     7  	"context"
     8  )
     9  
    10  const globalValueDelete = `-- name: GlobalValueDelete :exec
    11  DELETE
    12  FROM chart_global_values
    13  WHERE key = $1
    14    AND chart_type = $2
    15  `
    16  
    17  type GlobalValueDeleteParams struct {
    18  	Key       string
    19  	ChartType ChartType
    20  }
    21  
    22  func (q *Queries) GlobalValueDelete(ctx context.Context, arg GlobalValueDeleteParams) error {
    23  	_, err := q.db.ExecContext(ctx, globalValueDelete, arg.Key, arg.ChartType)
    24  	return err
    25  }
    26  
    27  const globalValueGet = `-- name: GlobalValueGet :one
    28  SELECT DISTINCT ON ("key") id, created, key, value, chart_type, encrypted
    29  FROM chart_global_values
    30  WHERE chart_type = $1 AND "key" = $2
    31  ORDER BY "key", "created" DESC
    32  `
    33  
    34  type GlobalValueGetParams struct {
    35  	ChartType ChartType
    36  	Key       string
    37  }
    38  
    39  func (q *Queries) GlobalValueGet(ctx context.Context, arg GlobalValueGetParams) (ChartGlobalValue, error) {
    40  	row := q.db.QueryRowContext(ctx, globalValueGet, arg.ChartType, arg.Key)
    41  	var i ChartGlobalValue
    42  	err := row.Scan(
    43  		&i.ID,
    44  		&i.Created,
    45  		&i.Key,
    46  		&i.Value,
    47  		&i.ChartType,
    48  		&i.Encrypted,
    49  	)
    50  	return i, err
    51  }
    52  
    53  const globalValueInsert = `-- name: GlobalValueInsert :exec
    54  INSERT INTO chart_global_values (
    55      "key",
    56      "value",
    57      "chart_type",
    58      "encrypted"
    59  ) VALUES (
    60      $1,
    61      $2,
    62      $3,
    63      $4
    64  )
    65  `
    66  
    67  type GlobalValueInsertParams struct {
    68  	Key       string
    69  	Value     string
    70  	ChartType ChartType
    71  	Encrypted bool
    72  }
    73  
    74  func (q *Queries) GlobalValueInsert(ctx context.Context, arg GlobalValueInsertParams) error {
    75  	_, err := q.db.ExecContext(ctx, globalValueInsert,
    76  		arg.Key,
    77  		arg.Value,
    78  		arg.ChartType,
    79  		arg.Encrypted,
    80  	)
    81  	return err
    82  }
    83  
    84  const globalValuesGet = `-- name: GlobalValuesGet :many
    85  SELECT DISTINCT ON ("key") id, created, key, value, chart_type, encrypted
    86  FROM chart_global_values
    87  WHERE chart_type = $1
    88  ORDER BY "key", "created" DESC
    89  `
    90  
    91  func (q *Queries) GlobalValuesGet(ctx context.Context, chartType ChartType) ([]ChartGlobalValue, error) {
    92  	rows, err := q.db.QueryContext(ctx, globalValuesGet, chartType)
    93  	if err != nil {
    94  		return nil, err
    95  	}
    96  	defer rows.Close()
    97  	items := []ChartGlobalValue{}
    98  	for rows.Next() {
    99  		var i ChartGlobalValue
   100  		if err := rows.Scan(
   101  			&i.ID,
   102  			&i.Created,
   103  			&i.Key,
   104  			&i.Value,
   105  			&i.ChartType,
   106  			&i.Encrypted,
   107  		); err != nil {
   108  			return nil, err
   109  		}
   110  		items = append(items, i)
   111  	}
   112  	if err := rows.Close(); err != nil {
   113  		return nil, err
   114  	}
   115  	if err := rows.Err(); err != nil {
   116  		return nil, err
   117  	}
   118  	return items, nil
   119  }