Fuse::DBI - mount your database as filesystem and use it

-= Fuse::DBI perl module with example script. Requires working FUSE perl bindings in form of Fuse module installed.
Currently, test with SQLite doesn't pass, but I'm working on it.
Fuse-DBI-0.08.tar.gz 13 Kb
-=> Latest source is always available from Subversion repository




Fuse::DBI - mount your database as filesystem and use it



  use Fuse::DBI;
  Fuse::DBI->mount( ... );

See run below for examples how to set parameters.



This module will use Fuse module, part of FUSE (Filesystem in USErspace) available at http://fuse.sourceforge.net/ to mount your database as file system.

That will give you possibility to use normal file-system tools (cat, grep, vi) to manipulate data in database.

It's actually opposite of Oracle's intention to put everything into database.




Mount your database as filesystem.

Let's suppose that your database have table files with following structure:

 id:		int
 filename:	text
 size:		int
 content:	text
 writable:	boolean

Following is example how to mount table like that to /mnt:

  my $mnt = Fuse::DBI->mount({
	'filenames' => 'select id,filename,size,writable from files',
	'read' => 'select content from files where id = ?',
	'update' => 'update files set content = ? where id = ?',
	'dsn' => 'DBI:Pg:dbname=test_db',
	'user' => 'database_user',
	'password' => 'database_password',
	'invalidate' => sub { ... },



SQL query which returns id (unique id for that row), filename, size and writable boolean flag.


SQL query which returns only one column with content of file and has placeholder ? for id.


SQL query with two pace-holders, one for new content and one for id.


DBI dsn to connect to (contains database driver and name of database).


User with which to connect to database


Password for connecting to database


Optional anonymous code reference which will be executed when data is updated in database. It can be used as hook to delete cache (for example on-disk-cache) which is created from data edited through Fuse::DBI.


Optional flag which forks after mount so that executing script will continue running. Implementation is experimental.

There is also alternative way which can generate read and update queries on the fly:

  my $mnt = Fuse::DBI->mount({
	'filenames' => 'select id,filename,size,writable from files',
	'read' => sub {
		my ($path,$file) = @_;
		return( 'select content from files where id = ?', $file->{row}->{id} );
	'update' => sub {
		my ($path,$file) = @_;
		return( 'update files set content = ? where id = ?', $file->{row}->{id} );
	'dsn' => 'DBI:Pg:dbname=test_db',
	'user' => 'database_user',
	'password' => 'database_password',
	'invalidate' => sub { ... },


Check if fuse filesystem is mounted

  if ($mnt->is_mounted) { ... }


Unmount your database as filesystem.


This will also kill background process which is translating database to filesystem.


Checks if fuse module is loaded in kernel.

  die "no fuse module loaded in kernel"
  	unless (Fuse::DBI::fuse_module_loaded);

This function in called by mount, but might be useful alone also.






Size information (ls -s) is wrong. It's a problem in upstream Fuse module (for which I'm to blame lately), so when it gets fixes, Fuse::DBI will automagically pick it up.



FUSE (Filesystem in USErspace) website http://fuse.sourceforge.net/

Example for WebGUI which comes with this distribution in directory examples/webgui.pl. It also contains a lot of documentation about design of this module, usage and limitations.



Dobrica Pavlinusic, <dpavlin@rot13.org>




2007-01-22 18:01:14 dpavlin r67

/trunk/Makefile.PL: use svk, cpan target

2007-01-22 18:00:58 dpavlin r66

/trunk/MANIFEST: removed old unneeded Fuse patches

2006-11-26 22:30:58 dpavlin r65

/trunk/DBI.pm: hush debug output

2006-11-26 22:29:23 dpavlin r64

/trunk/DBI.pm: first try at cleaning up the code. sleep after fusermount -u

2006-11-25 11:20:56 dpavlin r63

/trunk/fuse-perl-patch: removed obsolete fuse perl patch

2006-08-02 21:53:30 dpavlin r62

/trunk/DBI.pm: old changes from 2006-03-25 16:07 to support alternative code-ref parametars for filenames, read and update which enable query generation on the fly

2006-01-03 14:56:35 dpavlin r61

/trunk/DBI.pm: change %files -> $files

2006-01-03 14:19:04 dpavlin r60

/trunk/META.yml: added META.yml

2005-06-20 21:15:05 dpavlin r59

/trunk/t/02sqlite.t, /trunk/t/03pgsql.t: added tests for write to file (update database)

2005-04-29 16:05:31 dpavlin r58

/trunk/examples/strix-multi_static.pl, /trunk/examples/strix-static3.pl: use breadcrumbs for directories and files

2005-04-26 20:18:45 dpavlin r57

/trunk/MANIFEST: added Strix examples

2005-04-26 20:17:14 dpavlin r56

/trunk/examples/strix-multi_static.pl, /trunk/examples/strix-static3.pl: added examples for Strix portal (www.strix-portal.com)

2005-04-26 20:12:55 dpavlin r55

/trunk/DBI.pm: 0.08: support for filenames which are null (it will ne named NULL-id)

2005-04-26 19:57:51 dpavlin r54

/trunk/DBI.pm: better support for zero-sized files

2004-11-28 20:20:36 dpavlin r53

/trunk/DBI.pm: fixed work-around for non-working fusermount, removed some debugging output

2004-11-27 15:08:10 dpavlin r52

/trunk/DBI.pm: really remove all output from fusermount, define constant BLOCK to 1024 (used in various places)

2004-11-27 14:02:18 dpavlin r51

/trunk/Makefile.PL, /trunk/DBI.pm: Improvements in getattr and statfs: du will not return meaningful values and df will return something which is not as wrong as it was (but, still not correct).

Fuse::DBI will not try to load kernel module using sudo, and try to umount using sudo umount if fusermount -u fails (as it happends with current CVS version of fuse).

New webgui test target in Makefile which work as test on my local machine (and hopefully on any with webgui default installation).

2004-11-27 00:40:18 dpavlin r50

/trunk/MANIFEST: add patches

2004-11-26 21:34:02 dpavlin r49

/trunk/fuse-perl-patch/cvs-20041116.diff, /trunk/fuse-perl-patch/cvs-api_fix.diff, /trunk/fuse-perl-patch/cvs-blocks_fix.diff: rename one patch, added blocks fix

2004-11-24 10:24:07 dpavlin r48

/trunk/t/02sqlite.t: test cleanup

2004-11-23 23:54:58 dpavlin r47

/trunk/DBI.pm: API 0.07:
- added is_mounted
- mount will now block until filesystem is mounted (this might take up to 2 sec in intervals of 0.5 sec)

2004-11-23 23:52:06 dpavlin r46

/trunk/Changes: this will be generated from svn log

2004-11-23 23:49:24 dpavlin r45

/trunk/examples/webgui.pl: fix support for PostgreSQL

2004-11-23 11:16:41 dpavlin r44

/trunk/t/99pod.t: fix POD test

2004-11-23 11:16:32 dpavlin r43

/trunk/Makefile.PL: produce Changes from svn log

2004-11-23 11:03:38 dpavlin r42

/trunk/README: better explanation

2004-11-23 11:03:24 dpavlin r41

/trunk/t/99pod.t, /trunk/t/01load.t: fix tests to remove dependency on jsFind (and I souldn't copy tests between my modules anyway :-)

2004-11-19 21:56:12 dpavlin r40

/trunk/DBI.pm: fixed mounted mess. This will probably fix fusermount errors users are seeing once and forever. Added $SIG{'QUIT'} handler, documented bug in upstream Fuse module.

2004-11-16 16:00:52 dpavlin r39

/trunk/MANIFEST: added patch to MANIFEST

2004-11-16 15:59:04 dpavlin r38

/trunk/README: documentation update before release

2004-11-16 15:48:11 dpavlin r37

/trunk/fuse-perl-patch/cvs-20041116.diff, /trunk/fuse-perl-patch: patch to fix current CVS version of Fuse perl bindings

2004-11-16 15:34:25 dpavlin r36

/trunk/DBI.pm, /trunk/examples/webgui.pl: update URL to fuse web site

2004-11-16 15:32:36 dpavlin r35

/trunk/MANIFEST, /trunk/MANIFEST.SKIP: bookkeeping update before release

2004-11-16 15:32:21 dpavlin r34

/trunk/t/03pgsql.t: working PostgreSQL example

2004-11-15 20:55:10 dpavlin r33

/trunk/MANIFEST, /trunk/Makefile.PL, /trunk/t/02sqlite.t, /trunk/DBI.pm: SQLite test is finally working, bumped version to 0.05, you can really umount filesystem when using fork (which is still very experimental and useful only for tests anyway)

2004-11-15 20:45:03 dpavlin r32

/trunk/DBI.pm: fix quoting of characters in regex: Fuse::DBI will now work correctly with parens and other characters which have special meaning in regexps

2004-10-10 19:33:23 dpavlin r31

/trunk/DBI.pm: modify ctime only when writing to file, prevents message "file has changed"

2004-10-09 00:03:42 dpavlin r30

/trunk/MANIFEST, /trunk/DBI.pm: fix for pod2html

2004-10-08 23:44:34 dpavlin r29

/trunk/examples/webgui-mysql.pl: removed obsolete example

2004-10-08 23:43:06 dpavlin r28

/trunk/DBI.pm: documentation improvements, API 0.04

2004-10-08 22:56:55 dpavlin r27

/trunk/examples/webgui.pl, /trunk/Makefile.PL: use Data::Config from WebGUI installation to read configuration file and extract all needed data from it, added a lot of documentation and finished example for WebGUI

2004-10-08 22:55:36 dpavlin r26

/trunk/DBI.pm: added invalidation of file list with rmdir, prevent multiple umounts by keeping mounted flag

2004-10-08 20:07:32 dpavlin r25

/trunk/examples/webgui-mysql.pl: invalidate example

2004-10-08 20:07:12 dpavlin r24

/trunk/DBI.pm: call umount on DESTROY, support for optional 'invalidate' code ref which erase templates from disk (user running fuse must have permissions on template directory for this to work)

2004-10-02 16:54:42 dpavlin r23

/trunk/DBI.pm: correct links in pod to that pod2html doesn't choke

2004-10-02 16:30:16 dpavlin r22

/trunk/t/03pgsql.t, /trunk/t/02sqlite.t, /trunk/DBI.pm: fixed fork option and tests

2004-10-02 15:29:02 dpavlin r21

/trunk/DBI.pm: a lot of changes (0.03 API):
- added unlink (rm) method to invalidate in-memory cache
- added fuse_module_loaded method to check if fuse module is loaded
- fixed short read of last block
- removed Proc::Simple usage and replaced with simplier forking mechanism

This is first working version, but it's not binary-safe yet. NULL bytes are still problem.

2004-10-02 00:42:38 dpavlin r20

/trunk/t/03pgsql.t: added PostgreSQL test

2004-10-02 00:42:27 dpavlin r19

/trunk/t/02database.t, /trunk/t/02sqlite.t: moved sqlite test to 02sqlite.t

2004-09-05 16:59:41 dpavlin r18

/trunk/DBI.pm: broken version with DBD::SQLite (transaction problems)

2004-09-05 16:55:12 dpavlin r17

/trunk/t/02database.t: make files writable

2004-09-05 16:55:02 dpavlin r16

/trunk/Makefile.PL: quote module names

2004-09-05 16:04:35 dpavlin r15

/trunk/t/02database.t: use DBD::SQLite to run tests (if installed)

2004-08-29 20:56:23 dpavlin r14

/trunk/examples/webgui-mysql.pl: working example for MySQL installation of WebGUI

2004-08-29 20:12:37 dpavlin r13

/trunk/DBI.pm, /trunk/examples/webgui.pl: getdir fix, working WebGUI example

2004-08-29 19:16:01 dpavlin r12

/trunk/DBI.pm, /trunk/t/02database.t: umount works, as well as tests

2004-08-29 18:51:29 dpavlin r11

/trunk/DBI.pm, /trunk/examples/webgui.pl, /trunk/t/02database.t, /trunk/examples, /trunk/Makefile.PL: first try at making this module (late commit)

2004-08-29 17:52:02 dpavlin r10

/trunk/Makefile: created from Makefile.PL

2004-08-07 19:06:03 dpavlin r9

/trunk/DBI.pm, /trunk/t/99pod.t, /trunk/fuse_dbi.pl, /trunk/Makefile, /trunk/README, /trunk/t, /trunk/t/01load.t, /trunk/MANIFEST, /trunk/Makefile.PL, /trunk/Changes: move code to Fuse::DBI module (probably broken now)

2004-08-07 15:16:50 dpavlin r8

/trunk/fuse_dbi.pl: better output, read fixes, ctime preserved (so that vi won't complain that your file changed if you save changes and try that again)

2004-08-07 14:48:23 dpavlin r7

/trunk/fuse_dbi.pl: make updates really work

2004-08-04 16:17:09 dpavlin r6

/trunk/fuse_dbi.pl, /trunk/Makefile: first try at making it writable

2004-08-04 09:25:31 dpavlin r3

/trunk/Makefile, /trunk/fuse_dbi.pl: file reading fix

2004-08-04 09:03:05 dpavlin r2

/trunk/fuse_dbi.pl, /trunk/Makefile: directory browsing, Makefile for debugging

2004-08-04 08:58:46 dpavlin r1

/trunk, /trunk/fuse_dbi.pl: import FUSE perl module to connect to database via DBI