January 2019
Intermediate to advanced
520 pages
14h 32m
English
Before you can execute any query on a database, you have to establish a connection with the database you started in a container. Create a new Connection instance with the following command:
let conn = Connection::connect("postgres://postgres@localhost:5432", TlsMode::None).unwrap();
The created Connection instance has execute and query methods. The first method is used to execute SQL statements; the second is used to query data with SQL. Since we want to manage users, let's add three functions that we'll use with our Connection instance: create_table, create_user, and list_users.
The first function, create_table, creates a table for users:
fn create_table(conn: &Connection) -> Result<(), Error> { conn.execute("CREATE ...Read now
Unlock full access