Perl6 DBDI YAPC::EU 201008
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Perl6 DBDI YAPC::EU 201008

on

  • 2,159 views

Slides of my Perl 6 DBDI (database interface) talk at YAPC::EU in August 2010. Please also see the fun screencast that includes a live demo of perl6 using a perl5 DBI driver: ...

Slides of my Perl 6 DBDI (database interface) talk at YAPC::EU in August 2010. Please also see the fun screencast that includes a live demo of perl6 using a perl5 DBI driver: http://timbunce.blip.tv/file/3973550/

Statistics

Views

Total Views
2,159
Views on SlideShare
2,159
Embed Views
0

Actions

Likes
1
Downloads
9
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

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

Perl6 DBDI YAPC::EU 201008 Presentation Transcript

  • 1. DBDI for Perl6
  • 2. In 2007 I said...
  • 3. Database interfaces for open source languages suck
  • 4. They’re all limited They’re all different They’re all duplicating development effort
  • 5. We need a common database driver API for Perl 6 and Parrot
  • 6. But what?
  • 7. Mature, Stable, Functional, Object Oriented Well documented, with a test suite Well known to a wide user base Well known to driver developers
  • 8. JDBC No, not Java, just the JDBC API The class and method names, the semantics the documentation the test suite
  • 9. Actually, not plain JDBC Sanitize the worst influences of Java Easier to use for dynamic languages
  • 10. Your Code DBI v2 API DBI DBDI API DBD Database Client Library
  • 11. NO JDBC FOR THIS! Your Code DBI v2 API DBI DBDI API DBD USE JDBC Database Client Library FOR THIS
  • 12. How?
  • 13. java2perl6api Generates Perl 6 Role modules that mirror the API of specified Java Classes Originally a GSoC Project by Phil Crow in 2007 http://github.com/timbunce/java2perl6
  • 14. Recurses into types used Maps Java types to Perl6 $ java2perl6api --add_types jdbclib-typemap --outdir jdbclib java.sql.DriverManager perl6: Rakudo Perl 6, version 2010.07-39-gac8a2ae built on parrot 2.6.0 r48152 loading java.sql.DriverManager loading . java.sql.Connection loading . . java.sql.Array loading . . . java.sql.ResultSet loading . . . . java.io.Reader loading . . . . java.sql.Date loading . . . . java.sql.Ref loading . . . . java.sql.ResultSetMetaData loading . . . . . java.sql.Wrapper loading . . . . java.sql.RowId loading . . . . java.sql.SQLWarning loading . . . . . java.sql.SQLException loading . . . . java.sql.Statement ... wrote jdbclib/java/lang/Enum.pm6 - class java.lang.Enum wrote jdbclib/java/sql/CallableStatement.pm6 - interface java.sql.CallableStatement ... compiling jdbclib/java/sql/SQLException.pm6 - class java.sql.SQLException compiling jdbclib/java/sql/Statement.pm6 - interface java.sql.Statement ... Compiles to .pir for validation and speed
  • 15. public interface java.sql.Statement extends java.sql.Wrapper { public static final int SUCCESS_NO_INFO; public static final int EXECUTE_FAILED; public abstract boolean execute(java.lang.String) throws java.sql.SQLException; public abstract boolean execute(java.lang.String, int) throws java.sql.SQLException; ... }
  • 16. role java::sql::Statement does java::sql::Wrapper { method SUCCESS_NO_INFO (--> Int) is export { ... } method EXECUTE_FAILED (--> Int) is export { ... } multi method execute ( Str $v1, --> Bool ) { ... } # throws java.sql.SQLException multi method execute ( Str $v1, Int $v2, --> Bool ) { ... } # throws java.sql.SQLException ... }
  • 17. 2009
  • 18. MiniDBI (formerly “FakeDBI”) “a tiny subset of DBI in Perl 6” started by Martin Berends “hopefully be obsoleted ASAP” has PostgreSQL and MySQL drivers
  • 19. 2010
  • 20. DBDI A database driver manager and driver implementation framework in Perl 6 Uses the roles generated by running java2perl6api java.sql.DriverManager http://github.com/timbunce/DBDI
  • 21. It Runs! A working PostgreSQL driver is included in DBDI It’s very minimal today (August 2010) but it only took a few hours to write
  • 22. # --- DBDI usage example --- use v6; use DBDI; use DBDI::pglibpq; my $url = @*ARGS.shift || prompt "Enter a 'dbdi:driver:...' URL: "; my $con = DBDI::DriverManager.getConnection($url, 'testuser', 'testpass'); while prompt 'SQL: ' -> $sql { my $result = $con.createStatement.executeQuery($sql); my $meta = $result.getMetaData; my @names = map { $meta.getColumnLabel($_) }, 1..$meta.getColumnCount; say @names.join(", "); while ( $result.next ) { my @row = map { $result.getString($_) }, 1..@names.elems; say @row.join(", "); } }
  • 23. CURRENT SITUATION Your Code MiniDBI DBDI MiniDBI Drivers DBDI Drivers DB Client Libs BASIC BUT BARE FUNCTIONAL SKELETON
  • 24. Next steps?
  • 25. Build up a class/role hirearchy borrowing from open source JDBC drivers Separate driver-specific logic from driver- independant logic to make it easy to implement drivers Establish infrastructure for logging, exceptions etc.
  • 26. SOME POINT IN THE FUTURE Your Code MiniDBI Tests MiniDBI Framework DBDI Driver MiniDBI Drivers MiniDBI DBDI Driver DBDI Drivers SUCK BRAINZ FROM MiniDBI TRANSITION DB Client Libs DRIVERS INTO & TEST ENABLER DBDI DRIVERS
  • 27. SOME POINT IN THE FUTURE Your Code MiniDBI Framework DBDI Driver MiniDBI Drivers DBDI Drivers DB Client Libs Also ADD a DRIVER to access Perl5 DBI using blitzkost
  • 28. SOME POINT FURTHER IN THE FUTURE Your Code JDBC Test Suite DBI v1/v2/v3/* Sufficient Magic DBDI Framework Driver DBDI Drivers DB Client Libs
  • 29. Interested? Come and join in! dbdi-dev@perl.org #dbdi on irc.freenode.org