Exemple #1
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            var col = this.ReadCollection(db, s);
            var docs = col.GetIndexes();

            return new BsonArray(docs);
        }
Exemple #2
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            var col = this.ReadCollection(db, s);
            var query = this.ReadQuery(s);

            return col.Delete(query);
        }
Exemple #3
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            var col = this.ReadCollection(db, s);
            var newName = s.Scan(@"[\w-]+");

            return db.RenameCollection(col.Name, newName);
        }
Exemple #4
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            var col = this.ReadCollection(db, s);
            var doc = JsonSerializer.Deserialize(s).AsDocument;

            return col.Update(doc);
        }
Exemple #5
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            var id = this.ReadId(s);
            var metadata = JsonSerializer.Deserialize(s).AsDocument;

            return db.FileStorage.SetMetadata(id, metadata);
        }
Exemple #6
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            var col = this.ReadCollection(db, s);
            var index = s.Scan(this.FieldPattern).Trim();

            return col.DropIndex(index);
        }
Exemple #7
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            var cols = db.GetCollectionNames().OrderBy(x => x).ToArray();

            if (cols.Length == 0) return BsonValue.Null;

            return string.Join(Environment.NewLine, cols);
        }
Exemple #8
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            var col = this.ReadCollection(db, s);
            var query = this.ReadQuery(s);
            var skipLimit = this.ReadSkipLimit(s);
            var docs = col.Find(query, skipLimit.Key, skipLimit.Value);

            return new BsonArray(docs);
        }
Exemple #9
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            var col = this.ReadCollection(db, s);
            var filename = s.Scan(@".*");

            using (var sr = new StreamReader(filename, Encoding.UTF8))
            {
                var docs = JsonSerializer.DeserializeArray(sr);

                return col.InsertBulk(docs.Select(x => x.AsDocument));
            }
        }
Exemple #10
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            var col = this.ReadCollection(db, s);
            var value = JsonSerializer.Deserialize(s);

            if (value.IsArray)
            {
                return col.Insert(value.AsArray.RawValue.Select(x => x.AsDocument));
            }
            else
            {
                col.Insert(new BsonDocument(value.AsDocument));

                return BsonValue.Null;
            }
        }
Exemple #11
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            if (s.HasTerminated)
            {
                var files = db.FileStorage.FindAll().Select(x => x.AsDocument);

                return new BsonArray(files);
            }
            else
            {
                var id = this.ReadId(s);

                var files = db.FileStorage.Find(id).Select(x => x.AsDocument);

                return new BsonArray(files);
            }
        }
Exemple #12
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            var id = this.ReadId(s);
            var filename = s.Scan(@"\s*.*").Trim();

            var file = db.FileStorage.FindById(id);

            if (file != null)
            {
                file.SaveAs(filename, true);

                return file.AsDocument;
            }
            else
            {
                return false;
            }
        }
Exemple #13
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            var result = new StringBuilder();

            if (s.HasTerminated || s.Match("mem$"))
            {
                var mem = s.Match("mem$");

                result = DumpDatabase.Pages(db, mem);
            }
            else
            {
                var col = s.Scan(@"[\w-]+");
                var field = s.Scan(@"\s+\w+").Trim();

                result = DumpDatabase.Index(db, col, field);
            }

            return result.ToString();
        }
Exemple #14
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            var col = this.ReadCollection(db, s);
            var field = s.Scan(this.FieldPattern).Trim();
            var doc = JsonSerializer.Deserialize(s);

            if (doc.IsNull)
            {
                return col.EnsureIndex(field, false);
            }
            else if (doc.IsBoolean)
            {
                return col.EnsureIndex(field, doc.AsBoolean);
            }
            else
            {
                var options = db.Mapper.ToObject<IndexOptions>(doc.AsDocument);

                return col.EnsureIndex(field, options);
            }
        }
Exemple #15
0
 public BsonValue Execute(LiteDatabase db, StringScanner s)
 {
     return db.GetDatabaseInfo();
 }
Exemple #16
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            var col = this.ReadCollection(db, s);

            return col.Drop();
        }
Exemple #17
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            db.Rollback();

            return BsonValue.Null;
        }
Exemple #18
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            db.Commit();

            return BsonValue.Null;
        }
Exemple #19
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            db.BeginTrans();

            return BsonValue.Null;
        }
Exemple #20
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            var id = this.ReadId(s);

            return db.FileStorage.Delete(id);
        }