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/
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
...
}
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
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
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