Exemple #1
0
        public Employees(IDBDatabase database) : base(database)
        {
            Name          = "Employees";
            KeyPath       = "id";
            AutoIncrement = true;

            FirstName = new IDBIndex(this, "firstName", "firstName");
            LastName  = new IDBIndex(this, "lastName", "lastName");
            FullName  = new IDBIndex(this, "fullName", "firstName,lastName");
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DBCursorOptions"/> class.
        /// </summary>
        /// <param name="collection">The collection to query against.</param>
        /// <param name="selector">The selector query.</param>
        /// <param name="returnFields">The fields to be returned.</param>
        /// <param name="orderBy">The field or fields to order the results by.</param>
        /// <param name="numberToSkip">The number of results to skip.</param>
        /// <param name="numberToReturn">The number to return in a given batch.</param>
        /// <param name="limit">If specified, only this many results are returned.</param>
        /// <param name="explain">if set to <c>true</c> a query explanation will be included.</param>
        /// <param name="snapshot">if set to <c>true</c> then execute against a data snapshot.</param>
        /// <param name="flags">The option flags.</param>
        /// <param name="explicitIndexHint">The explicit index hint.</param>
        public DBCursorOptions(IDBCollection collection,
            DBQuery selector = null,
            DBFieldSet returnFields = null,
            DBFieldSet orderBy = null,
            int? numberToSkip = null,
            int? numberToReturn = null,
            int? limit = null,
            bool explain = false,
            bool snapshot = false,
            CursorFlags flags = CursorFlags.None,
            IDBIndex explicitIndexHint = null)
        {
            Condition.Requires(snapshot, "snapshot")
                .Evaluate(!(snapshot && explicitIndexHint != null), "Snapshot is not allowed when there is an explicit hint")
                .Evaluate(!(snapshot && orderBy != null), "Snapshot is not allowed when there field set to order by");
            Condition.Requires(numberToReturn, "numberToReturn")
                .Evaluate(!(numberToReturn.HasValue && limit.HasValue), "You may not specify both numberToReturn AND limit. They are ways to set a common property. Choose one to set.");

            Collection = collection;
            Selector = selector ?? DBQuery.SelectAll;
            ReturnFields = returnFields;
            Explain = explain;
            Flags = flags;
            Hint = explicitIndexHint;
            OrderBy = orderBy;
            Snapshot = snapshot;

            if (numberToSkip.HasValue)
                NumberToSkip = numberToSkip;
            if (numberToReturn.HasValue)
                NumberToReturn = numberToReturn.Value;
            if (limit.HasValue)
                Limit = limit;

            //If we have special query details
            if (OrderBy != null && OrderBy.Keys.Any() ||
                Hint != null ||
                Explain)
            {
                //Push everything into a container
                DBQuery query = Selector;
                Selector = new DBQuery();
                Selector["query"] = query;
                if (OrderBy != null && OrderBy.Keys.Any())
                    Selector["orderby"] = OrderBy;
                if (Hint != null)
                    Selector["$hint"] = Hint.Name;
                if (Explain)
                    Selector["$explain"] = true;
                if (Snapshot)
                    Selector["$snapshot"] = true;
            }
        }
Exemple #3
0
 public IndexNode(IDBIndex index, CollectionNode parent)
     : base(parent)
 {
     Index = index;
 }
Exemple #4
0
 public void SetIndex(IDBIndex dbIndex, int indexNum)
 {
     _index    = dbIndex;
     _indexNum = indexNum;
 }