Skip to content

Instantly share code, notes, and snippets.

Created June 3, 2014 15:11
Show Gist options
  • Save anonymous/847c3585815d6788452f to your computer and use it in GitHub Desktop.
Save anonymous/847c3585815d6788452f to your computer and use it in GitHub Desktop.
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