Perl6 DBDI YAPC::EU 201008

2,020 views
1,933 views

Published on

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/

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

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

No notes for slide

Perl6 DBDI YAPC::EU 201008

  1. 1. DBDI for Perl6
  2. 2. In 2007 I said...
  3. 3. Database interfaces for open source languages suck
  4. 4. They’re all limited They’re all different They’re all duplicating development effort
  5. 5. We need a common database driver API for Perl 6 and Parrot
  6. 6. But what?
  7. 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. 8. JDBC No, not Java, just the JDBC API The class and method names, the semantics the documentation the test suite
  9. 9. Actually, not plain JDBC Sanitize the worst influences of Java Easier to use for dynamic languages
  10. 10. Your Code DBI v2 API DBI DBDI API DBD Database Client Library
  11. 11. NO JDBC FOR THIS! Your Code DBI v2 API DBI DBDI API DBD USE JDBC Database Client Library FOR THIS
  12. 12. How?
  13. 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. 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. 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. 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. 17. 2009
  18. 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. 19. 2010
  20. 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. 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. 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. 23. CURRENT SITUATION Your Code MiniDBI DBDI MiniDBI Drivers DBDI Drivers DB Client Libs BASIC BUT BARE FUNCTIONAL SKELETON
  24. 24. Next steps?
  25. 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. 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. 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. 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. 29. Interested? Come and join in! dbdi-dev@perl.org #dbdi on irc.freenode.org

×