DBD::SQ...Content(3)

πŸ’– DBD::SQLite::VirtualTable::FileContent(3) πŸ’–

okay so bestie, this is a page from the User Contributed Perl Documentation, and it's about DBD::SQLite::VirtualTable::FileContent β€” literally a virtual table for viewing file contents. yes, you heard me. files. in your database. slay. πŸŽ€


✨ NAME ✨

DBD::SQLite::VirtualTable::FileContent β€” a virtual table for viewing file contents. that's the whole vibe, no cap. πŸ¦‹


🌸 SYNOPSIS 🌸

so first, inside Perl, you register the module like this:

$dbh->sqlite_create_module(fcontent => "DBD::SQLite::VirtualTable::FileContent");

then, inside SQL, you do the iconic part:

CREATE VIRTUAL TABLE tbl USING fcontent(
   source      = src_table,
   content_col = content,
   path_col    = path,
   expose      = "path, col1, col2, col3", -- or "*"
   root        = "/foo/bar"
   get_content = Foo::Bar::read_from_file
);

and then you can literally just go:

SELECT col1, path, content FROM tbl WHERE ...;

periodt. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so a "FileContent" virtual table is bound to some underlying source table β€” and that source table has a column holding paths to files. the virtual table then behaves like a database view on top of the source table, except it's got one extra column that exposes the actual content from those files. it's giving "view but make it read your filesystem". ✨

and here's where it highkey shines: it's especially useful as an "external content" for some fulltext table (peep DBD::SQLite::Fulltext_search). the index table stores some metadata about files, and then the fulltext engine can index both the metadata and the file contents. obsessed. πŸ”₯


🌈 PARAMETERS 🌈

the parameters for creating a "FileContent" virtual table get specified right inside the "CREATE VIRTUAL TABLE" statement β€” just like regular column declarations, except with an '=' sign. the authorized parameters are, in order, bestie:

  • "source" β€” the name of the source table. this one is mandatory, like non-negotiable. all the other parameters are optional. πŸ‘‘
  • "content_col" β€” the name of the virtual column that exposes the file contents. the default is "content". πŸ“
  • "path_col" β€” the name of the column in "source" that contains the paths to the files. the default is "path". 🌸
  • "expose" β€” a comma-separated list (within double quotes) of source column names to be exposed by the virtual table. the default is "*", which means, yep, all source columns. πŸ’œ
  • "root" β€” an optional root directory that gets prepended to the path column when opening files. πŸŽ€
  • "get_content" β€” the fully qualified name of a Perl function for reading file contents. the default implementation just slurps the entire file into a string, but this hook can point to more sophisticated implementations β€” like, for example, a function that would remove html tags. the hooked function gets called like this:
$file_content = $get_content->($path, $root);

iykyk. 🧚


πŸ‘‘ AUTHOR πŸ‘‘

Laurent Dami <dami@cpan.org> β€” thank you for your service, icon. 🫢


Copyright Laurent Dami, 2014.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


okay bye bestie, go index some files πŸ’– β€” this page came from perl v5.42.0, dated 2024-10-19, filed under DBD::SQ...Content(3). mwah. πŸ’…βœ¨

πŸ“¦ where this page comes from