Exemplo n.º 1
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            var col = this.ReadCollection(db, s);
            var query = this.ReadQuery(s);

            return col.Delete(query);
        }
Exemplo n.º 2
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            var col = this.ReadCollection(db, s);
            var docs = col.GetIndexes();

            return new BsonArray(docs);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 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();
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 15
0
 public bool IsCommand(StringScanner s)
 {
     return s.Match(@"db\.info$");
 }
Exemplo n.º 16
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            var col = this.ReadCollection(db, s);

            return col.Drop();
        }
Exemplo n.º 17
0
 public bool IsCommand(StringScanner s)
 {
     return this.IsCollectionCommand(s, "drop[iI]ndex");
 }
Exemplo n.º 18
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            db.Rollback();

            return BsonValue.Null;
        }
Exemplo n.º 19
0
 public bool IsCommand(StringScanner s)
 {
     return this.IsCollectionCommand(s, "find");
 }
Exemplo n.º 20
0
 public bool IsCommand(StringScanner s)
 {
     return s.Scan(@"dump\s*").Length > 0;
 }
Exemplo n.º 21
0
 public bool IsCommand(StringScanner s)
 {
     return s.Scan(@"rollback(\s+trans)?$").Length > 0;
 }
Exemplo n.º 22
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            db.BeginTrans();

            return BsonValue.Null;
        }
Exemplo n.º 23
0
 public bool IsCommand(StringScanner s)
 {
     return s.Match(@"show\scollections");
 }
Exemplo n.º 24
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            db.Commit();

            return BsonValue.Null;
        }
Exemplo n.º 25
0
 public bool IsCommand(StringScanner s)
 {
     return this.IsFileCommand(s, "delete");
 }
Exemplo n.º 26
0
        public BsonValue Execute(LiteDatabase db, StringScanner s)
        {
            var id = this.ReadId(s);

            return db.FileStorage.Delete(id);
        }
Exemplo n.º 27
0
 public bool IsCommand(StringScanner s)
 {
     return this.IsFileCommand(s, "download");
 }
Exemplo n.º 28
0
 public BsonValue Execute(LiteDatabase db, StringScanner s)
 {
     return db.GetDatabaseInfo();
 }