{"id":17071663,"url":"https://github.com/alranel/dbix-lite","last_synced_at":"2025-04-12T19:52:55.115Z","repository":{"id":2417974,"uuid":"3386310","full_name":"alranel/DBIx-Lite","owner":"alranel","description":"Chained and minimal ORM","archived":false,"fork":false,"pushed_at":"2024-10-31T17:10:01.000Z","size":157,"stargazers_count":12,"open_issues_count":7,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-12T19:52:40.476Z","etag":null,"topics":["cpan","dbi","perl"],"latest_commit_sha":null,"homepage":"","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alranel.png","metadata":{"files":{"readme":"README.pod","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-02-08T10:46:11.000Z","updated_at":"2025-01-24T23:31:39.000Z","dependencies_parsed_at":"2025-02-22T01:31:00.992Z","dependency_job_id":"9c0627d7-0408-4a52-a902-acb482983441","html_url":"https://github.com/alranel/DBIx-Lite","commit_stats":null,"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alranel%2FDBIx-Lite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alranel%2FDBIx-Lite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alranel%2FDBIx-Lite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alranel%2FDBIx-Lite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alranel","download_url":"https://codeload.github.com/alranel/DBIx-Lite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248625508,"owners_count":21135513,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpan","dbi","perl"],"created_at":"2024-10-14T11:37:14.574Z","updated_at":"2025-04-12T19:52:55.081Z","avatar_url":"https://github.com/alranel.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"=pod\n\n=encoding UTF-8\n\n=head1 NAME\n\nDBIx::Lite - Chained and minimal ORM\n\n=head1 VERSION\n\nversion 0.37\n\n=head1 SYNOPSIS\n\n    use DBIx::Lite;\n    \n    my $dbix = DBIx::Lite-\u003enew(driver_name =\u003e 'Pg');  # disconnected mode\n    my $dbix = DBIx::Lite-\u003enew(dbh =\u003e $dbh);\n    my $dbix = DBIx::Lite-\u003econnect(\"dbi:Pg:dbname=$db\", $user, $passwd, {pg_enable_utf8 =\u003e 1});\n    \n    # build queries using chained methods -- no schema definition required\n    my $authors_rs = $dbix-\u003etable('authors');\n    my $authors_rs = $dbix-\u003etable('authors')-\u003esearch({ country =\u003e 'IT' });\n    my $books_rs = $dbix\n        -\u003etable('books')\n        -\u003eselect('id', 'title', 'year')\n        -\u003eleft_join('authors', { author_id =\u003e 'id' })\n        -\u003eselect_also(['authors.name' =\u003e 'author_name'])\n        -\u003eorder_by('year');\n    \n    # retrieve rows and columns -- still no schema definition required\n    my @authors = $authors_rs-\u003eall;\n    my $author = $authors_rs-\u003esearch({ id =\u003e 1 })-\u003esingle;\n    while (my $book = $books_rs-\u003enext) {\n        printf \"%s (%s)\\n\", $book-\u003etitle, $book-\u003eauthor_name;  # automatic accessor methods\n    }\n    my @author_names = $authors_rs-\u003eget_column('name');\n    my $book_count = $books_rs-\u003ecount;\n    \n    # manipulate rows\n    my $book = $dbix-\u003etable('books')-\u003einsert({ name =\u003e 'Camel Tales', year =\u003e 2012 });\n    $books_rs-\u003esearch({ year =\u003e { '\u003c' =\u003e 1920 } })-\u003eupdate({ very_old =\u003e 1 });\n    $authors_rs-\u003esearch({ age =\u003e { '\u003e' =\u003e 99 } })-\u003edelete;\n    \n    # define a primary key and get more features\n    $dbix-\u003eschema-\u003etable('authors')-\u003eautopk('id');\n    my $author = $dbix_lite-\u003etable('authors')-\u003efind(2);\n    $author-\u003eupdate({ age =\u003e 40 });\n    $author-\u003edelete;\n    \n    # define relationships\n    $dbix-\u003eschema-\u003eone_to_many('authors.id' =\u003e 'books.author_id', 'author');\n    my $author = $books-\u003eauthor;\n    my $books_rs = $author-\u003ebooks-\u003esearch({ year =\u003e 2012 });\n    my $book = $author-\u003einsert_related('books', { title =\u003e \"A Camel's Life\" });\n    \n    # define custom object classes\n    $dbix-\u003eschema\n        -\u003etable('subjects')\n        -\u003eclass('My::Subject')\n        -\u003eresultset_class('My::Subject::ResultSet');\n\n=head1 ABSTRACT\n\nMany ORMs and DBI abstraction layers are available on CPAN, one of the most notables\nbeing L\u003cDBIx::Class\u003e which provides the most powerful features to handle database\ncontents using OOP.\n\nDBIx::Lite was written with some goals in mind, that no other available module provides.\nSuch goals/key features are:\n\n=over 4\n\n=item no need to define your database schema (most features work without one and some advanced features only require some bits, and still not the full table definitions)\n\n=item no need to connect to database: the module can just generate SQL for you\n\n=item chained methods with lazy SQL generation\n\n=item joins/relationships\n\n=item optional custom classes for results and resultsets with custom methods\n\n=item L\u003cSQL::Abstract\u003e syntax\n\n=item paging features (with L\u003cData::Page\u003e)\n\n=back\n\n=head1 METHODS\n\nInstantiating a DBIx::Lite object isn't more difficult than just writing:\n\n    my $dbix = DBIx::Lite-\u003enew(driver_name =\u003e 'Pg');\n\nDriver name is the name of the DBI module you expect to use. We need to specify it as the\ngenerated SQL will depend on the driver.\nThis constructor will give you an unconnected object, that you can use to generate SQL commands using\nthe L\u003cselect_sql()\u003e, L\u003cinsert_sql()\u003e, L\u003cupdate_sql()\u003e and L\u003cdelete_sql()\u003e methods without \nexecuting it.\n\nIf you want to connect to a database you can pass a pre-connected database handle with the \nC\u003cdbh\u003e argument or you can supply your connection options to the C\u003cconnect()\u003e method. All\narguments passed to C\u003cconnect()\u003e will be just passed to L\u003cDBIx::Connector\u003e which will be\nused to manage your connection under the hood.\n\n    my $dbix = DBIx::Lite-\u003enew(dbh =\u003e $dbh);\n    my $dbix = DBIx::Lite-\u003econnect(\"dbi:Pg:dbname=$db\", $user, $passwd, {pg_enable_utf8 =\u003e 1});\n\nNote that C\u003cconnect()\u003e can be called as an object method too, if you want to connect an\nunconnected DBIx::Lite object at a later stage:\n\n    my $dbix = DBIx::Lite-\u003enew;\n    $dbix-\u003econnect(\"dbi:Pg:dbname=$db\", $user, $passwd);\n\n=head2 new\n\nThis class method may accept the following optional arguments:\n\n=over 4\n\n=item I\u003cdbh\u003e\n\nThis argument allows you to supply a pre-made L\u003cDBI\u003e database handle. See the example in \nthe previous paragraph.\n\n=item I\u003cconnector\u003e\n\nThis argument allows you to supply a pre-made L\u003cDBIx::Connector\u003e object.\n\n=item I\u003cschema\u003e\n\nThis argument allows you to supply a pre-made L\u003cDBIx::Lite::Schema\u003e object. If none is\nprovided, a new empty one will be created for each DBIx::Lite object. This argument is\nuseful if you want to prepare your schema in advance and reutilize it across multiple\nconnections.\n\n=item I\u003cabstract\u003e\n\nThis argument allows you to supply options for L\u003cSQL::Abstract::More\u003e module. Here is \nexample for MySQL DB backend to quote fields names with backtick to allow using reserved\nwords as column's names.\n\n    my $dbix = DBIx::Lite-\u003enew( abstract =\u003e { quote_char =\u003e '`', name_sep =\u003e '.' } );\n    $dbix-\u003econnect(\"DBI:mysql:$db_dbname;host=$db_host\", $db_username, $db_password); \n\n=back\n\n=head2 connect\n\nThis methods accepts a list of arguments that are passed to L\u003cDBIx::Connector\u003e. It \nreturns the DBIx::Lite object. It can be called either as class or object method.\n\n=head2 table\n\nThis method accepts a table name and returns a L\u003cDBIx::Lite::ResultSet\u003e object on which\nyou can chain its methods to build your query.\n\n    my $rs = $dbix-\u003etable('books');\n\n=head2 schema\n\nThis method returns our L\u003cDBIx::Lite::Schema\u003e object which may hold the definitions\nrequired for some advanced feature of DBIx::Lite. You can call then call its methods:\n\n    $dbix-\u003eschema-\u003etable('authors')-\u003eautopk('id');\n\nSee the L\u003cDBIx::Lite::Schema\u003e documentation for an explanation of its methods.\n\n=head2 dbh\n\nThis method returns a L\u003cDBI\u003e database handle that you can use to perform manual queries.\n\n=head2 txn\n\nThis method accepts a coderef which will be run inside a transaction.\n\n    $dbix-\u003etxn(sub {\n        $dbix-\u003etable('books')-\u003eupdate({ year =\u003e 2015 });\n    });\n\n=for Pod::Coverage dbh_do driver_name\n\n=head1 AUTHOR\n\nAlessandro Ranellucci \u003caar@cpan.org\u003e\n\n=head1 COPYRIGHT AND LICENSE\n\nThis software is copyright (c) 2024 by Alessandro Ranellucci.\n\nThis is free software; you can redistribute it and/or modify it under\nthe same terms as the Perl 5 programming language system itself.\n\n=cut\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falranel%2Fdbix-lite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falranel%2Fdbix-lite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falranel%2Fdbix-lite/lists"}