package main
import (
"context"
"fmt"
"os"
"github.com/jackc/pgx/v4"
)
func main() {
cfg := "postgres://postgres:2887@localhost:5432/productdb"
conn, err := pgx.Connect(context.Background(), cfg)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err)
os.Exit(1)
}
defer conn.Close(context.Background())
var model string
var company string
err = conn.QueryRow(context.Background(), "select model, company from products where id=$1", 42).Scan(&model, &company)
if err != nil {
fmt.Fprintf(os.Stderr, "QueryRow failed: %v\n", err)
os.Exit(1)
}
fmt.Println(model, company)
}
Unable to connect to database: failed to connect to `host=localhost
user=postgres database=productdb`:
failed to receive message (unexpected EOF)
exit status 1
func main() {
psqlInfo := fmt.Sprintf("host=%s port=%d user=%s "+
"password=%s dbname=%s sslmode=disable",
host, port, user, password, dbname)
db, err := sql.Open("postgres", psqlInfo)
if err != nil {
panic(err)
}
defer db.Close()
err = db.Ping()
if err != nil {
panic(err)
}
fmt.Println("Successfully connected!")
}
<template>
<select v-model="selected">
<option value="form1">Форма №1</option>
<option value="form2">Форма №2</option>
<option value="form3">Форма №3</option>
</select>
<form v-show="selected === form1" class="formGroup">
<input type="text" placeholder="Форма №1">
</form>
<form v-show="selected === form2" class="formGroup">
<input type="text" c placeholder="Форма №2">
</form>
<form v-show="selected === form3" class="formGroup">
<input type="text" placeholder="Форма №3">
</form>
</template>
<script>
export default {
data() {
return {
selected: '',
}
},
}
</script>
<select v-model="selected">
<option value="form1">Форма №1</option>
<option value="form2">Форма №2</option>
<option value="form3">Форма №3</option>
</select>
<form v-show="v-model_selected === form1" class="formGroup">
<input type="text" placeholder="Форма №1">
</form>
<form v-show="v-model_selected === form2" class="formGroup">
<input type="text" c placeholder="Форма №2">
</form>
<form v-show="v-model_selected === form3" class="formGroup">
<input type="text" placeholder="Форма №3">
</form>