Created
June 3, 2014 15:11
-
-
Save anonymous/847c3585815d6788452f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pg' | |
require 'pry' | |
conn = PG.connect(dbname: 'chinook') | |
def add_artist(db_conn, name) | |
sql = <<-SQL | |
INSERT INTO artists (name) | |
VALUES ($1) RETURNING id | |
SQL | |
db_conn.exec_params(sql, [name]).first["id"] | |
end | |
def update_artist(db_conn, id, new_name) | |
sql = <<-SQL | |
UPDATE artists | |
SET name=$1 | |
WHERE id=$2 | |
SQL | |
db_conn.exec_params(sql, [new_name, id]) | |
end | |
id = add_artist(conn,"Steven and the t-shirts") | |
update_artist(conn, id, "S7even && le t-shirts") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment