Skip to content

Instantly share code, notes, and snippets.

@dkubb
Created August 29, 2010 06:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkubb/556033 to your computer and use it in GitHub Desktop.
Save dkubb/556033 to your computer and use it in GitHub Desktop.
DO API ideas
connection = DataObjects::Connection.new(uri)
connection.close
# immediately executed statements
reader = connection.query('SELECT * FROM table WHERE id = ?', 1)
reader.set_types(Integer) # returns self for chaining
reader.each { |row| ... }
result = connection.execute('INSERT INTO table (id) VALUES(?)', 1)
result.insert_id
result.affected_rows
# prepared statements
statement = connection.prepare('SELECT * FROM table WHERE id = ?')
bound = statement.bind(1)
bound.each { |row| ... }
statement = connection.prepare('INSERT INTO table (id) VALUES(?)')
result = statement.execute(1)
# or maybe
bound = statement.bind(1)
bound.execute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment