Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Euruko 2009 - DataObjects

2,756 views

Published on

Slides from the Euruko 2009 talk on DataObjects, the unified database access API for Ruby

Published in: Technology
  • Be the first to comment

Euruko 2009 - DataObjects

  1. 1. DataObjects
  2. 2. Dirkjan Bussink
  3. 3. © Jon Truran
  4. 4. Text Sorry for the photoshop skills...
  5. 5. connection = Mysql.real_connect(quot;localhostquot;, quot;rootquot;, quot;quot;, quot;do_testquot;) reader = connection.query(quot;SELECT login, password FROM usersquot;) reader.each do |row| row[0] => 'dbussink' row[1] => 'secret' end connection = OCI8.new(quot;rootquot;, quot;quot;, quot;localhostquot;) reader = connection.exec(quot;SELECT login, password FROM usersquot;) while row = reader.fetch row[0] => 'dbussink' row[1] => 'secret' end connection = PGconn.connect(quot;localhostquot;, 5432, nil, nil, quot;do_testquot;, quot;rootquot;, quot;quot;) reader = connection.exec(quot;SELECT login, password FROM usersquot;) for i in 0...reader.ntuples do reader.getvalue(i,0) => 'dbussink' reader.getvalue(i,1) => 'secret' end connection = SQLite3::Database.new(quot;do_test.dbquot;) reader = connection.execute(quot;SELECT login, password FROM usersquot;) reader[0][0] => 'dbussink' reader[0][1] => 'secret'
  6. 6. It’s all about the API
  7. 7. connection = DataObjects::Connection.new(quot;mysql://root@localhost/do_testquot;) command = connection.create_command(quot;INSERT INTO users (login) VALUES ('dbussink')quot;) result = command.execute_non_query result.affected_rows => 1 result.insert_id => 2
  8. 8. connection = DataObjects::Connection.new(quot;mysql://root@localhost/do_testquot;) command = connection.create_command(quot;SELECT id, login, created_at FROM usersquot;) reader = command.execute_reader reader.fields => ['id', 'login', 'created_at'] while reader.next! reader.values => [1, 'dbussink', Date.civil(2009, 5, 10)] end
  9. 9. Typecasting
  10. 10. connection = DataObjects::Connection.new(quot;mysql://root@localhost/do_testquot;) command = connection.create_command(quot;SELECT id, login, created_at FROM usersquot;) command.set_types(String, String, String) reader = command.execute_reader reader.fields => ['id', 'login', 'created_at'] while reader.next! reader.values => ['1', 'dbussink', '2009-5-10'] end
  11. 11. connection = DataObjects::Connection.new(quot;mysql://root@localhost/do_testquot;) command = connection.create_command(quot;SELECT id, login, password FROM users WHERE login = ?quot;) reader = command.execute_reader('dbussink') reader.fields => ['id', 'login', 'created_at'] while reader.next! reader.values => [1, 'dbussink', Date.civil(2009, 5, 10)] end
  12. 12. Float String Integer Date BigDecimal TrueClass DateTime
  13. 13. Shared specs
  14. 14. describe DataObjects::Postgres::Command do it_should_behave_like 'a Command' it_should_behave_like 'a Command with async' end
  15. 15. Implement standard Command API describe DataObjects::Postgres::Command do it_should_behave_like 'a Command' it_should_behave_like 'a Command with async' end
  16. 16. Implement standard Command API describe DataObjects::Postgres::Command do it_should_behave_like 'a Command' it_should_behave_like 'a Command with async' end Command is green thread friendly
  17. 17. describe 'DataObjects::Postgres with BigDecimal' do it_should_behave_like 'supporting BigDecimal' it_should_behave_like 'supporting BigDecimal autocasting' end
  18. 18. Deserialize and serialize BigDecimal describe 'DataObjects::Postgres with BigDecimal' do it_should_behave_like 'supporting BigDecimal' it_should_behave_like 'supporting BigDecimal autocasting' end
  19. 19. Deserialize and serialize BigDecimal describe 'DataObjects::Postgres with BigDecimal' do it_should_behave_like 'supporting BigDecimal' it_should_behave_like 'supporting BigDecimal autocasting' end Database provides a mapped type (DECIMAL)
  20. 20. How can I help?
  21. 21. Improved transactions
  22. 22. Prepared statements
  23. 23. Specs! And documentation too :)
  24. 24. ActiveRecord adapter

×