Labkey::Query
use Labkey::Query; my $results = Labkey::Query::selectRows( -baseUrl => 'http://labkey.com:8080/labkey/', -containerPath => 'myFolder/', -schemaName => 'lists', -queryName => 'mid_tags', );
For interacting with data in LabKey Server
This module is designed to simplify querying and manipulating data in LabKey Server. It should more or less replicate the javascript APIs of the same names.
After the module is installed, you will need to create a .netrc file in the home directory of the user running the perl script. Documentation on .netrc can be found here: https://www.labkey.org/wiki/home/Documentation/page.view?name=netrc
The LabKey client APIs are described in greater detail here: https://www.labkey.org/wiki/home/Documentation/page.view?name=viewAPIs
Support questions should be directed to the LabKey forum: https://www.labkey.org/announcements/home/Server/Forum/list.view?
Ben Bimber
Copyright (c) 2010 Ben Bimber
Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
selectRows() can be used to query data from LabKey server
The following are the minimum required params:
my $results = Labkey::Query::selectRows( -baseUrl => 'http://labkey.com:8080/labkey/', -containerPath => 'myFolder/', -schemaName => 'lists', -queryName => 'mid_tags', );
The following are optional:
-viewName => 'view1', -filterArray => [ ['file_active', 'eq', 1], ['species', 'neq', 'zebra'] ], -maxRows => 10 #the max number of rows returned -sort => 'ColumnA,ColumnB' #sort order used for this query -offset => 100 #the offset used when running the query -columns => 'ColumnA,ColumnB' #A comma-delimited list of column names to include in the results. -containerFilter => 'currentAndSubfolders' -debug => 1, #will result in a more verbose output
NOTE: The environment variable 'LABKEY_URL' can be used instead of supplying a '-baseUrl' param
insertRows() can be used to insert records into a LabKey table
my $insert = Labkey::Query::insertRows( -baseUrl => 'http://labkey.com:8080/labkey/', -containerPath => 'myFolder/', -schemaName => 'lists', -queryName => 'backup', -rows => [{ "JobName" => 'jobName', "Status" => $status, "Log" => $log, "Date" => $date }], );
-debug => 1, #will result in a more verbose output
updateRows() can be used to update records in a LabKey table
my $update = Labkey::Query::updateRows( -baseUrl => 'http://labkey.com:8080/labkey/', -containerPath => 'myFolder/', -schemaName => 'lists', -queryName => 'backup', -rows => [{ "JobName" => 'jobName', "Status" => $status, "Log" => $log, "Date" => $date }], );
deleteRows() can be used to delete records in a LabKey table
my $update = Labkey::Query::deleteRows( -baseUrl => 'http://labkey.com:8080/labkey/', -containerPath => 'myFolder/', -schemaName => 'lists', -queryName => 'backup', -rows => [{ "Key" => '12', }], );
executeSql() can be used to execute arbitrary SQL
my $result = Labkey::Query::executeSql( -baseUrl => 'http://labkey.com:8080/labkey/', -containerPath => 'myFolder/', -schemaName => 'study', -sql => 'select MyDataset.foo, MyDataset.bar from MyDataset', );
-maxRows => 10 #the max number of rows returned -sort => 'ColumnA,ColumnB' #sort order used for this query -offset => 100 #the offset used when running the query -containerFilter => 'currentAndSubfolders' -debug => 1, #will result in a more verbose output
To install Labkey::Query, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Labkey::Query
CPAN shell
perl -MCPAN -e shell install Labkey::Query
For more information on module installation, please visit the detailed CPAN module installation guide.