Created
August 29, 2010 06:26
-
-
Save dkubb/556033 to your computer and use it in GitHub Desktop.
DO API ideas
This file contains hidden or 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
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