File: README.md

package info (click to toggle)
golang-github-jackc-pgx 4.18.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 796 kB
  • sloc: sh: 44; sql: 8; makefile: 7
file content (67 lines) | stat: -rw-r--r-- 1,868 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Description

This is a sample todo list implemented using pgx as the connector to a
PostgreSQL data store.

# Usage

Create a PostgreSQL database and run structure.sql into it to create the
necessary data schema.

Example:

    createdb todo
    psql todo < structure.sql

Build todo:

    go build

## Connection configuration

The database connection is configured via DATABASE_URL and standard PostgreSQL environment variables (PGHOST, PGUSER, etc.)

You can either export them then run todo:

    export PGDATABASE=todo
    ./todo list

Or you can prefix the todo execution with the environment variables:

    PGDATABASE=todo ./todo list

## Add a todo item

    ./todo add 'Learn go'

## List tasks

    ./todo list

## Update a task

    ./todo update 1 'Learn more go'

## Delete a task

    ./todo remove 1

# Example Setup and Execution

    jack@hk-47~/dev/go/src/github.com/jackc/pgx/examples/todo$ createdb todo
    jack@hk-47~/dev/go/src/github.com/jackc/pgx/examples/todo$ psql todo < structure.sql
    Expanded display is used automatically.
    Timing is on.
    CREATE TABLE
    Time: 6.363 ms
    jack@hk-47~/dev/go/src/github.com/jackc/pgx/examples/todo$ go build
    jack@hk-47~/dev/go/src/github.com/jackc/pgx/examples/todo$ export PGDATABASE=todo
    jack@hk-47~/dev/go/src/github.com/jackc/pgx/examples/todo$ ./todo list
    jack@hk-47~/dev/go/src/github.com/jackc/pgx/examples/todo$ ./todo add 'Learn Go'
    jack@hk-47~/dev/go/src/github.com/jackc/pgx/examples/todo$ ./todo list
    1. Learn Go
    jack@hk-47~/dev/go/src/github.com/jackc/pgx/examples/todo$ ./todo update 1 'Learn more Go'
    jack@hk-47~/dev/go/src/github.com/jackc/pgx/examples/todo$ ./todo list
    1. Learn more Go
    jack@hk-47~/dev/go/src/github.com/jackc/pgx/examples/todo$ ./todo remove 1
    jack@hk-47~/dev/go/src/github.com/jackc/pgx/examples/todo$ ./todo list