github.com/blend/go-sdk@v1.20220411.3/examples/db/statement-timeout/seed.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package main
     9  
    10  import (
    11  	"context"
    12  
    13  	"github.com/blend/go-sdk/db"
    14  )
    15  
    16  const (
    17  	dropTable     = "DROP TABLE IF EXISTS might_sleep;"
    18  	createTable   = "CREATE TABLE might_sleep ( id INTEGER NOT NULL );"
    19  	tableSeedData = "INSERT INTO might_sleep (id) VALUES (1337);"
    20  )
    21  
    22  func seedDatabase(ctx context.Context, pool *db.Connection) error {
    23  	_, err := pool.ExecContext(ctx, dropTable)
    24  	if err != nil {
    25  		return err
    26  	}
    27  
    28  	_, err = pool.ExecContext(ctx, createTable)
    29  	if err != nil {
    30  		return err
    31  	}
    32  
    33  	_, err = pool.ExecContext(ctx, tableSeedData)
    34  	return err
    35  }