#  Copyright (c) 1997-2018
#  Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
#  http://www.polymake.org
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version: http://www.gnu.org/licenses/gpl.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#-------------------------------------------------------------------------------
#
#  This file is part of the polymake database interface polyDB.
#
#   @author Silke Horn, Andreas Paffenholz
#   http://solros.de
#   http://www.mathematik.tu-darmstadt.de/~paffenholz
#


CREDIT polyDB

use MongoDB;
use MongoDB::OID;

# @topic property_types/DBCursor
# @category Database
# A database cursor. Initialize it with a database name, a collection name and a query.
# You can then iterate over the objects matching the query with next.
# It lazily fetches more objects from the database server.
# (Note that you have to create a new cursor if you want to start from the beginning.)

# @category Database
# Returns a cursor on the entries for the database //db// in //collection// that match the //query//.
# @param HASH query database query
# @option String db database name
# @option String collection collection name
# @option Int skip skip the first elements, default: 0
# @option Int limit limit the number of objects that will be returned (default: no limit)
# @option HASH sort_by sorting of the entries, default by _id
# @option String username
# @option String password
# @option MongoClient client
# @option Bool local set to 1 if you want to use a local database (on localhost), default 0
# @return DBCursor
user_function db_cursor ($; {db         => $PolyDB::default::db_database_name, \
                             collection => $PolyDB::default::db_collection_name, \
                             skip       => 0, \
                             limit      => 0, \
                             sort_by    => {_id => 1}, \
                             username   => $PolyDB::default::db_user, \
                             password   => $PolyDB::default::db_pwd, \
                             client     => undef, \
                             local      => 0 }) \
{
   my ($query, $options) = @_;
   my $dbc = new PolyDB::DBCursor($query,$options);
   return $dbc;
}


# Local Variables:
# mode: perl
# cperl-indent-level:3
# indent-tabs-mode:nil
# End:
