Euruko 2009 - DataObjects
Upcoming SlideShare
Loading in...5
×
 

Euruko 2009 - DataObjects

on

  • 2,739 views

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

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

Statistics

Views

Total Views
2,739
Views on SlideShare
2,730
Embed Views
9

Actions

Likes
2
Downloads
9
Comments
0

2 Embeds 9

http://www.slideshare.net 8
http://www.lmodules.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Euruko 2009 - DataObjects Euruko 2009 - DataObjects Presentation Transcript

  • 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 = 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'
  • It’s all about the API
  • 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
  • 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
  • Typecasting
  • 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
  • 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
  • Float String Integer Date BigDecimal TrueClass DateTime
  • Shared specs
  • describe DataObjects::Postgres::Command do it_should_behave_like 'a Command' it_should_behave_like 'a Command with async' end
  • Implement standard Command API describe DataObjects::Postgres::Command do it_should_behave_like 'a Command' it_should_behave_like 'a Command with async' end
  • 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
  • describe 'DataObjects::Postgres with BigDecimal' do it_should_behave_like 'supporting BigDecimal' it_should_behave_like 'supporting BigDecimal autocasting' end
  • Deserialize and serialize BigDecimal describe 'DataObjects::Postgres with BigDecimal' do it_should_behave_like 'supporting BigDecimal' it_should_behave_like 'supporting BigDecimal autocasting' end
  • 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)
  • How can I help?
  • Improved transactions
  • Prepared statements
  • Specs! And documentation too :)
  • ActiveRecord adapter