# Copyright (c) 2013-2016 Silke Horn, Andreas Paffenholz
# http://solros.de/polymake/poly_db
# http://www.mathematik.tu-darmstadt.de/~paffenholz
# 
# This file is part of the polymake extension polyDB.
# 
# polyDB 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 3 of the License, or
# (at your option) any later version.
# 
# polyDB 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.
# 
# You should have received a copy of the GNU General Public License
# along with polyDB.  If not, see <http://www.gnu.org/licenses/>.

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 limit limit the number of objects that will be returned (default: no limit)
# @option Int skip skip the first elements, default: 0
# @option HASH sort_by sorting of the entries, default by _id
# @option Bool local set to 1 if you want to use a local database (on localhost), default 0
# @option String username
# @option String password
# @option MongoClient client
# @return DBCursor
user_function db_cursor ($; {db => $db_database_name, collection => $db_collection_name, local => 0, limit => 0, username => $db_user, password => $db_pwd, client => undef, skip => 0, sort_by => {_id => 1}}) {
	my ($query, $options) = @_;
	my $dbc = new PolyDB::DBCursor($query,$options);
	return $dbc;
}
