An admin application for editing database, but with configurable features (grouping and ordering of tables and columns, hyperlink navigation between related records, etc.)
1. 24.08.2014 - Page 1
Département
OfficeApp::AutoCRUD
An application for searching and
manipulating data in relational
databases
YAPC::EU::2014
laurent.dami@justice.ge.ch
Etat de Genève, Pouvoir Judiciaire
Département
Office
4. Business need : tool for the support team
Regular
Users
database
Regular
App
Database
Admins
Admin
Tools
Support
Team
? ? ?
5. Data access for support team
Needs
• Browse DB schema
• CRUD on all data
• Navigate
– Follow relationships
– Optimize for most common
tables and colums
Solutions
• Program an admin GUI
– too much work !
• Give them DBA tools
– too low-level
– no customization
Need a CRUD app !
7. App::AutoCRUD main features
• Powerful search syntax
• Distinctive URL for every resource
– no session, all information in URL
– easy admin links from the "real App"
• Joins as hyperlinks
• Bulk update / delete operations
• Customizable table order / column order
• Navigation through tree navigator
8. 24.08.2014 - Page 1
Département
Office
Quick overview
To run the demo :
cd examples
perl download_db.pl
plackup
20. ± RESTful URLs
• /Chinook/table/Track/search?GenreId=1,3&Name=Ab*
– GET display pre-filled search form
– POST redirect to list
• /Chinook/table/Track/list?GenreId=1,3&Name=Ab*
– search results
• /Chinook/table/Track/id/399
– single record
• /Chinook/table/Track/delete?where_pk.TrackId=399
– GET display pre-filled delete form
– POST database operation
Note : browser-oriented, not API-oriented
No use of HTTP methods PUT and DELETE
25. "crud.psgi" startup file
use App::AutoCRUD;
use YAML qw/LoadFile/;
my $config = LoadFile "/path/to/config.yaml";
my $crud = App::AutoCRUD->new(config => $config);
my $app = $crud->to_app;
26. Start the application
• From the command line
plackup crud.psgi
• Within Apache
<Location /crud>
SetHandler perl-script
PerlResponseHandler Plack::Handler::Apache2
PerlSetVar psgi_app /path/to/crud.psgi
</Location>
• Other possibilities : see L<Plack>
29. Infrastructure modules
• Moose for OO
– Modern Perl OO framework
• YAML for config data
– Human-readable
– Support for directed acyclic graph (DAG) reusable subtrees
– But can be replaced by JSON, XML, Config::General or Perl source code
• Data::Domain for data validation
30. Controller modules
• Plack for HTTP support
– Abstraction over various engines
– Many middleware options
• CGI::Expand for transforming form inputs
– <input name="foo.1.bar" value=1234>
– { foo => [ {...}, { bar => 1234 } ] }
• SQL::Abstract::FromQuery for parsing user queries
– HTML form SQL::Abstract::More SQL
– Parses booleans, < > !=, LIKE, BETWEEN, etc.
31. Model modules
• DBI for database independance
– Perl standard for databases
• DBIx::DataModel for object-relational mapping
– Why not DBIC ? See
http://www.slideshare.net/ldami/dbixclass-vs-
dbixdatamodel
• SQL::Abstract::More for SQL generation
– Emit SQL from Perl datastructures
32. View modules
• Template Toolkit for HTML generation
• Alien::GvaScript for widgets
– Tree::Navigator
• Prototype.js for Javascript abstraction
– Navigator abstraction, OO programming, etc.
• Excel::Writer::XLSX for generating Excel worksheets
–
35. App::AutoCRUD
• Entry point
• Autodiscovers component subclasses
• isa Plack::Component
• Has
– Name
– Config
– Datasources
36. App::AutoCRUD::DataSource
• Encapsulates DBIx::DataModel schema
– Autogenerate Perl code if not already present
• Gathers and merges metadata
– From the DB schema
• Tables, columns, foreign keys
– From config
• Table groups, column groups, ordering, display parameters
37. App::AutoCRUD::Context
• Gathers contextual information for the current request
– Plack::Request object
– Datasource object
– View to apply
– Parameters for the view (for example TT template name)
47. Status
• Still young, lots of TODO
• Already in production at Geneva Justice
• Has some original features not seen other CRUD apps
• Could be useful for many people
– Also outside the Perl community
• Perl marketing needs general-purpose apps
– Needs stabilization & doc
– Needs marketing
– You can help !