File: db_query.rules

package info (click to toggle)
polymake 4.3-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 31,528 kB
  • sloc: cpp: 152,204; perl: 43,222; javascript: 30,700; ansic: 2,937; java: 2,654; python: 641; sh: 244; xml: 117; makefile: 62
file content (158 lines) | stat: -rw-r--r-- 6,276 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#  Copyright (c) 1997-2020
#  Ewgenij Gawrilow, Michael Joswig, and the polymake team
#  Technische Universität Berlin, Germany
#  https://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://www.mathematik.tu-darmstadt.de/~paffenholz
#


# FIMXE page of Silke is gone!
# FIXME we need a page in the wiki

use namespaces qw(+ PolyDB);

CREDIT polyDB

package PolyDB::default;

# @category Database Access
# polyDB: The hostname of the database, default 'polymake.org'
custom $db_host = "db.polymake.org";

# polyDB: The port of the database, default 27017
custom $db_port = "27017";

# polyDB: The name of the database for the collections
custom $db_name = "polydb";

# polyDB: The database username, default 'polymake'
custom $db_user = "polymake";

# polyDB: The database password, default 'database'
custom $db_pwd = "database";

# polyDB: The name of the section you want to access. Set this if you want to access a certain section all (or most of) the time.
custom $db_section_name = "";

# polyDB: The name of the collection you want to access. Set this if you want to access a certain collection all (or most of) the time.
custom $db_collection_name = "";

# polyDB: the version of polyDB used
custom $db_polydb_version = "2.1";

# polyDB: The timeout for waiting to get a socket connection to the db server
custom $db_socket_timeout = 120000;

# polyDB: The color for section names in info output
custom $db_section_color = 'bold red';

# polyDB: The color for collection names in info output
custom $db_collection_color = 'bold yellow';

# polyDB: Whether to use SSL
custom $useSSL = 1;

# polyDB: whether some pretty printing shoudl be applied for the info method
#         needs to be switched off for testing
custom $pretty_print_doc = true;

# polyDB: The name of the authentication database, default 'admin'
custom $db_auth_db = "admin";

package PolyDB::Collection;

# @category Database Query Operations
# Common options for database queries
options %query_options = (
   # [complete PolyDB::query(grouped)] ARRAY sort returned objects by given properties
   #  sort criteria are specified as list of pairs (PROPERTY_NAME => 1|-1), -1 meaning descending order.
   #  By default, objects are sorted by _id
   sort_by => [ _id => 1 ],
   # [complete PolyDB::query(grouped)] HASH filter for properties in returned objects: { PROPERTY_NAME => 0|1, ... }
   #  All values in the filter must be either 0's or 1's.
   #  A filter with zero values suppresses the specified properties and allows all others,
   #  while a filter with ones allows the specified properties and suppresses all others.
   #  By default, objects are returned with all properties stored in the database.
   projection => undef,
   # [complete PolyDB::query(grouped)] Bool return objects as json
   raw => false
);

# @category Database Query Operations
# Options for database queries returning a cursor
options %cursor_options = (
   %query_options,
   # Int  maximal number of objects to be returned; by default, no limit
   limit => 0,
   # Int  skip that many first elements; default is 0
   skip => 0
);

# @category Database Query Operations
# Retrieve all objects satisfying the given search criteria
# @param [complete PolyDB::query(grouped)] HASH query search criteria written in Mongo query language
#  an empty hash map will retrieve all objects in this collection
# @options %cursor_options
# @return PolyDB::Cursor cursor over results
user_method find ($, %cursor_options) {
   my ($collection, $query, $options) = @_;
   return $collection->make_cursor($query, $options->{projection}, $options->{raw})->limit($options->{limit})->skip($options->{skip})->sort($options->{sort_by});
}

# @category Database Query Operations
# Retrieve the first object satisfying the given search criteria.
# @param [complete PolyDB::query(grouped)] HASH query search criteria written in Mongo query language
#  an empty hash map will retrieve a random object from this collection
# @return Core::BigObject
user_method find_one ($, \%query_options) {
   my ($collection, $query, $options) = @_;
   return $collection->find_one_impl($query, $options->{projection}, $options->{sort_by}, $options->{raw});
}

# @category Database Query Operations
# Retrieve a list of distinct values of a given property.
# The values are returned in arbitrary order.
# @param [complete PolyDB::query(grouped)] HASH query search criteria for objects to be inspected, written in Mongo query language
#  an empty hash map will collect property values from all objects in this collection
# @param [complete PolyDB::query] String property name of the property of interest
# @return ARRAY
user_method distinct ($$) { &distinct_impl }

# @category Database Query Operations
# Return the number of objects satisfying the given search criteria.
# @param [complete PolyDB::query(grouped)] HASH query search criteria written in Mongo query language
user_method count ($) { &count_impl }

# @category Database Query Operations
# Count the distinct property values in objects satisfying the given search criteria.
# @param [complete PolyDB::query(grouped)] HASH query search criteria for objects to be inspected, written in Mongo query language
#  an empty hash map will collect property values from all objects in this collection
# @param [complete PolyDB::query] String property name of the property of interest
user_method count_distinct ($$) {
   if (defined(my $result = count_distinct_impl(@_, "n"))) {
      $result->{n}
   } else {
      0
   }
}

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