DataObjects
Dirkjan Bussink
© Jon Truran
Text




Sorry for the photoshop skills...
connection = Mysql.real_connect(quot;localhostquot;, quot;rootquot;, quot;quot;, quot;do_testquot;)
 reader     = connecti...
It’s all about the API
connection = DataObjects::Connection.new(quot;mysql://root@localhost/do_testquot;)
command    = connection.create_command(...
connection = DataObjects::Connection.new(quot;mysql://root@localhost/do_testquot;)
command    = connection.create_command(...
Typecasting
connection = DataObjects::Connection.new(quot;mysql://root@localhost/do_testquot;)
command    = connection.create_command(...
connection = DataObjects::Connection.new(quot;mysql://root@localhost/do_testquot;)

command    = connection.create_command...
Float
                     String
Integer

                                    Date
                BigDecimal


         ...
Shared specs
describe DataObjects::Postgres::Command do
  it_should_behave_like 'a Command'
  it_should_behave_like 'a Command with asy...
Implement standard
                                                   Command API
describe DataObjects::Postgres::Command ...
Implement standard
                                                   Command API
describe DataObjects::Postgres::Command ...
describe 'DataObjects::Postgres with BigDecimal' do
  it_should_behave_like 'supporting BigDecimal'
  it_should_behave_lik...
Deserialize and
                                                   serialize BigDecimal

describe 'DataObjects::Postgres w...
Deserialize and
                                                       serialize BigDecimal

describe 'DataObjects::Postgr...
How can I help?
Improved transactions
Prepared statements
Specs!
And documentation too :)
ActiveRecord adapter
Euruko 2009 - DataObjects
Euruko 2009 - DataObjects
Euruko 2009 - DataObjects
Euruko 2009 - DataObjects
Euruko 2009 - DataObjects
Euruko 2009 - DataObjects
Euruko 2009 - DataObjects
Euruko 2009 - DataObjects
Euruko 2009 - DataObjects
Euruko 2009 - DataObjects
Euruko 2009 - DataObjects
Euruko 2009 - DataObjects
Euruko 2009 - DataObjects
Euruko 2009 - DataObjects
Euruko 2009 - DataObjects
Upcoming SlideShare
Loading in …5
×

Euruko 2009 - DataObjects

2,324 views
2,251 views

Published on

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

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,324
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
10
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

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

×