github.com/jackc/pgx/v5@v5.5.5/examples/todo/README.md (about) 1 # Description 2 3 This is a sample todo list implemented using pgx as the connector to a 4 PostgreSQL data store. 5 6 # Usage 7 8 Create a PostgreSQL database and run structure.sql into it to create the 9 necessary data schema. 10 11 Example: 12 13 createdb todo 14 psql todo < structure.sql 15 16 Build todo: 17 18 go build 19 20 ## Connection configuration 21 22 The database connection is configured via DATABASE_URL and standard PostgreSQL environment variables (PGHOST, PGUSER, etc.) 23 24 You can either export them then run todo: 25 26 export PGDATABASE=todo 27 ./todo list 28 29 Or you can prefix the todo execution with the environment variables: 30 31 PGDATABASE=todo ./todo list 32 33 ## Add a todo item 34 35 ./todo add 'Learn go' 36 37 ## List tasks 38 39 ./todo list 40 41 ## Update a task 42 43 ./todo update 1 'Learn more go' 44 45 ## Delete a task 46 47 ./todo remove 1 48 49 # Example Setup and Execution 50 51 jack@hk-47~/dev/go/src/github.com/jackc/pgx/examples/todo$ createdb todo 52 jack@hk-47~/dev/go/src/github.com/jackc/pgx/examples/todo$ psql todo < structure.sql 53 Expanded display is used automatically. 54 Timing is on. 55 CREATE TABLE 56 Time: 6.363 ms 57 jack@hk-47~/dev/go/src/github.com/jackc/pgx/examples/todo$ go build 58 jack@hk-47~/dev/go/src/github.com/jackc/pgx/examples/todo$ export PGDATABASE=todo 59 jack@hk-47~/dev/go/src/github.com/jackc/pgx/examples/todo$ ./todo list 60 jack@hk-47~/dev/go/src/github.com/jackc/pgx/examples/todo$ ./todo add 'Learn Go' 61 jack@hk-47~/dev/go/src/github.com/jackc/pgx/examples/todo$ ./todo list 62 1. Learn Go 63 jack@hk-47~/dev/go/src/github.com/jackc/pgx/examples/todo$ ./todo update 1 'Learn more Go' 64 jack@hk-47~/dev/go/src/github.com/jackc/pgx/examples/todo$ ./todo list 65 1. Learn more Go 66 jack@hk-47~/dev/go/src/github.com/jackc/pgx/examples/todo$ ./todo remove 1 67 jack@hk-47~/dev/go/src/github.com/jackc/pgx/examples/todo$ ./todo list