Skip to content

Commit

Permalink
Merge pull request #17 from mbdavid/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
mbdavid committed Mar 28, 2015
2 parents 15cc6a2 + aa3a8ed commit cf80c93
Show file tree
Hide file tree
Showing 191 changed files with 7,414 additions and 7,325 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 Mauricio David
Copyright (c) 2014-2015 Mauricio David

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions LiteDB.Shell/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
</configuration>
12 changes: 8 additions & 4 deletions LiteDB.Shell/Commands/Close.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@

namespace LiteDB.Shell.Commands
{
internal class Close : IShellCommand
internal class Close : ConsoleCommand
{
public bool IsCommand(StringScanner s)
public override bool IsCommand(StringScanner s)
{
return s.Scan(@"close$").Length > 0;
}

public void Execute(LiteEngine db, StringScanner s, Display display)
public override void Execute(LiteShell shell, StringScanner s, Display display, InputCommand input)
{
db.Dispose();
if (shell.Database == null) throw LiteException.NoDatabase();

shell.Database.Dispose();

shell.Database = null;
}
}
}
6 changes: 3 additions & 3 deletions LiteDB.Shell/Commands/Comment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

namespace LiteDB.Shell.Commands
{
internal class Comment : IShellCommand
internal class Comment : ConsoleCommand
{
public bool IsCommand(StringScanner s)
public override bool IsCommand(StringScanner s)
{
return s.Match(@"--");
}

public void Execute(LiteEngine db, StringScanner s, Display display)
public override void Execute(LiteShell shell, StringScanner s, Display display, InputCommand input)
{
}
}
Expand Down
38 changes: 38 additions & 0 deletions LiteDB.Shell/Commands/Ed.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

namespace LiteDB.Shell.Commands
{
internal class Ed : ConsoleCommand
{
public override bool IsCommand(StringScanner s)
{
return s.Match(@"ed$");
}

public override void Execute(LiteShell shell, StringScanner s, Display display, InputCommand input)
{
var temp = Path.GetTempPath() + "LiteDB.Shell.txt";

// remove "ed" command from history
input.History.RemoveAt(input.History.Count - 1);

var last = input.History.Count > 0 ? input.History[input.History.Count - 1] : "";

File.WriteAllText(temp, last.Replace("\n", Environment.NewLine));

Process.Start("notepad.exe", temp).WaitForExit();

var text = File.ReadAllText(temp);

if (text == last) return;

input.Queue.Enqueue(text);
}
}
}
150 changes: 87 additions & 63 deletions LiteDB.Shell/Commands/Help.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,84 +6,108 @@

namespace LiteDB.Shell.Commands
{
internal class Help : IShellCommand
internal class Help : ConsoleCommand
{
public bool IsCommand(StringScanner s)
public override bool IsCommand(StringScanner s)
{
return s.Scan(@"help$").Length > 0;
return s.Scan(@"help\s*").Length > 0;
}

public void Execute(LiteEngine db, StringScanner s, Display d)
public override void Execute(LiteShell shell, StringScanner s, Display d, InputCommand input)
{
d.WriteResult("Shell commands");
d.WriteResult("==============");
var sb = new StringBuilder();
var full = s.Match("full");

d.WriteHelp("> open <filename>", "Open a new database");
d.WriteHelp("> close", "Close current database");
d.WriteHelp("> run <filename>", "Run commands inside filename");
d.WriteHelp("> pretty on|off", "Turns on/off pretty json format");
d.WriteHelp("> timer", "Show timer before prompt");
d.WriteHelp("> ed", "Open nodepad with last command to edit and execute");
d.WriteHelp("> spool on|off", "Spool all output in a spool file");
d.WriteHelp("> -- comment", "Do nothing, its just a comment");
d.WriteHelp("> /<command>/", "Support for multi line command");
d.WriteHelp("> exit", "Close LiteDB shell");
if (!full)
{
d.WriteHelp("Basic Shell Commands - try `help full` for all commands");
d.WriteHelp("=======================================================");

d.WriteResult("");
d.WriteResult("Transaction commands");
d.WriteResult("====================");
d.WriteHelp("> db.<collection>.insert <jsonDoc>", "Insert a new document into collection");
d.WriteHelp("> db.<collection>.update <jsonDoc>", "Update a document inside collection");
d.WriteHelp("> db.<collection>.delete <filter>", "Delete documents using a filter clausule (see find)");
d.WriteHelp("> db.<collection>.find <filter> [skip N][limit N]", "Show filtered documents based on index search");
d.WriteHelp("> db.<collection>.count <filter>", "Show count rows according query filter");
d.WriteHelp("> db.<collection>.ensureIndex <field> [true|{options}]", "Create a new index document field. For unique key, use true");
d.WriteHelp("> db.<collection>.indexes", "List all indexes in this collection");
d.WriteHelp("<filter> = <field> [=|>|>=|<|<=|!=|like|between] <jsonValue>", "Filter query syntax");
d.WriteHelp("<filter> = (<filter> [and|or] <filter> [and|or] ...)", "Multi queries syntax");

d.WriteHelp("> begin", "Begins a new transaction");
d.WriteHelp("> commit", "Commit current transaction");
d.WriteHelp("> rollback", "Rollback current transaction");
d.WriteHelp("Try:");
d.WriteHelp(" > db.customers.insert { _id:1, name:\"John Doe\", age: 37 }");
d.WriteHelp(" > db.customers.ensureIndex name");
d.WriteHelp(" > db.customers.find name like \"John\"");
d.WriteHelp(" > db.customers.find (name like \"John\" and _id between [0, 100]) limit 10");
}
else
{
d.WriteHelp("Shell commands");
d.WriteHelp("==============");

d.WriteResult("");
d.WriteResult("Collections commands");
d.WriteResult("====================");
d.WriteHelp("> open <filename>", "Open a new database");
d.WriteHelp("> close", "Close current database");
d.WriteHelp("> run <filename>", "Run commands inside filename");
d.WriteHelp("> pretty on|off", "Turns on/off pretty json format");
d.WriteHelp("> timer", "Show timer before prompt");
d.WriteHelp("> ed", "Open nodepad with last command to edit and execute");
d.WriteHelp("> spool on|off", "Spool all output in a spool file");
d.WriteHelp("> -- comment", "Do nothing, its just a comment");
d.WriteHelp("> /<command>/", "Support for multi line command");
d.WriteHelp("> version", "Show LiteDB version");
d.WriteHelp("> exit", "Close LiteDB shell");

d.WriteHelp("> db.<collection>.insert <jsonDoc>", "Insert a new document into collection");
d.WriteHelp("> db.<collection>.update <jsonDoc>", "Update a document inside collection");
d.WriteHelp("> db.<collection>.delete <filter>", "Delete documents using a filter clausule (see find)");
d.WriteHelp("> db.<collection>.bulk <filename>", "Bulk insert a json file as documents");
d.WriteHelp("> db.<collection>.find [top N]", "Show all documents. Can limit results in N documents");
d.WriteHelp("> db.<collection>.find [top N] <filter>", "Show filtered documents based on index search");
d.WriteHelp("> db.<collection>.count <filter>", "Show count rows according query filter");
d.WriteHelp("> db.<collection>.exec <filter> { Action<Object (id), BsonDocument (doc), Collection (col), LiteEngine (db)> }", "Execute C# code for each document based on filter.");
d.WriteHelp("> db.<collection>.ensureIndex <field> [unique]", "Create a new index document field");
d.WriteHelp("> db.<collection>.indexes", "List all indexes in this collection");
d.WriteHelp("> db.<collection>.drop", "Drop collection and destroy all documents inside");
d.WriteHelp("> db.<collection>.dropIndex <field>", "Drop a index and make index area free to use with another index");
d.WriteHelp("<filter> = <field> [=|>|>=|<|<=|!=|like|between] <jsonValue>", "Filter query syntax");
d.WriteHelp("<filter> = (<filter> [and|or] <filter> [and|or] ...)", "Multi queries syntax");
d.WriteHelp("<jsonDoc> = {_id: ... , key: value, key1: value1 }", "Represent a json (extended version) for a BsonDocument. See special data types");
d.WriteHelp("JsonEx Date", "{ mydate: { $date :\"2015-01-01T23:59:59Z\"} }");
d.WriteHelp("JsonEx Guid", "{ myguid: { $guid :\"3a1c34b3-9f66-4d8e-975a-d545d898a4ba\"} }");
d.WriteHelp("JsonEx Binary", "{ mydata: { $binary :\"base64 byte array\"} }");
d.WriteHelp();
d.WriteHelp("Transaction commands");
d.WriteHelp("====================");

d.WriteResult("");
d.WriteResult("File storage commands");
d.WriteResult("=====================");
d.WriteHelp("> begin", "Begins a new transaction");
d.WriteHelp("> commit", "Commit current transaction");
d.WriteHelp("> rollback", "Rollback current transaction");

d.WriteHelp("> fs.find", "List all files on datafile");
d.WriteHelp("> fs.find <fileId>", "List file info from a key. Supports * for starts with key");
d.WriteHelp("> fs.upload <fileId> <filename>", "Insert a new file inside database");
d.WriteHelp("> fs.download <fileId> <filename>", "Save a file to disk passing a file key and filename");
d.WriteHelp("> fs.update <fileId> {key:value}", "Update metadata file");
d.WriteHelp("> fs.delete <fileId>", "Remove a file inside database");
d.WriteHelp();
d.WriteHelp("Collections commands");
d.WriteHelp("====================");

d.WriteResult("");
d.WriteResult("Other commands");
d.WriteResult("==============");
d.WriteHelp("> db.<collection>.insert <jsonDoc>", "Insert a new document into collection");
d.WriteHelp("> db.<collection>.update <jsonDoc>", "Update a document inside collection");
d.WriteHelp("> db.<collection>.delete <filter>", "Delete documents using a filter clausule (see find)");
d.WriteHelp("> db.<collection>.bulk <filename>", "Bulk insert a json file as documents");
d.WriteHelp("> db.<collection>.find [skip N][limit N]", "Show all documents. Can limit/skip results");
d.WriteHelp("> db.<collection>.find <filter> [skip N][limit N]", "Show filtered documents based on index search. See <filter> syntax below");
d.WriteHelp("> db.<collection>.count <filter>", "Show count rows according query filter");
d.WriteHelp("> db.<collection>.exec <filter> { Action<Object (id), BsonDocument (doc), Collection (col), LiteDatabase (db)> }", "Execute C# code for each document based on filter.");
d.WriteHelp("> db.<collection>.ensureIndex <field> [unique]", "Create a new index document field");
d.WriteHelp("> db.<collection>.indexes", "List all indexes in this collection");
d.WriteHelp("> db.<collection>.drop", "Drop collection and destroy all documents inside");
d.WriteHelp("> db.<collection>.dropIndex <field>", "Drop a index and make index area free to use with another index");
d.WriteHelp("> db.<collection>.rename <newCollectionName>", "Rename a collection");
d.WriteHelp("> db.<collection>.min <field>", "Returns min/first value from collection using index field");
d.WriteHelp("> db.<collection>.max <field>", "Returns max/last value from collection using index field");
d.WriteHelp("<filter> = <field> [=|>|>=|<|<=|!=|like|contains|in|between] <jsonValue>", "Filter query syntax");
d.WriteHelp("<filter> = (<filter> [and|or] <filter> [and|or] ...)", "Multi queries syntax");
d.WriteHelp("<jsonDoc> = {_id: ... , key: value, key1: value1 }", "Represent a json (extended version) for a BsonDocument. See special data types");
d.WriteHelp("Json Date", "{ mydate: { $date :\"2015-01-01T23:59:59Z\"} }");
d.WriteHelp("Json Guid", "{ myguid: { $guid :\"3a1c34b3-9f66-4d8e-975a-d545d898a4ba\"} }");
d.WriteHelp("Json Binary", "{ mydata: { $binary :\"base64 byte array\"} }");

d.WriteHelp("> db.info", "Get database informations");
d.WriteHelp("> dump", "Display dump database information");
d.WriteHelp();
d.WriteHelp("File storage commands");
d.WriteHelp("=====================");

d.WriteResult("");
d.WriteResult("Try:");
d.WriteResult(" > db.customers.insert { _id:1, name:\"John Doe\", age: 37 }");
d.WriteResult(" > db.customers.ensureIndex name");
d.WriteResult(" > db.customers.find name like \"J\"");
d.WriteResult(" > db.customers.find _id > 0");
d.WriteHelp("> fs.find", "List all files on datafile");
d.WriteHelp("> fs.find <fileId>", "List file info from a key. Supports * for starts with key");
d.WriteHelp("> fs.upload <fileId> <filename>", "Insert a new file inside database");
d.WriteHelp("> fs.download <fileId> <filename>", "Save a file to disk passing a file key and filename");
d.WriteHelp("> fs.update <fileId> {key:value}", "Update metadata file");
d.WriteHelp("> fs.delete <fileId>", "Remove a file inside database");

d.WriteHelp();
d.WriteHelp("Other commands");
d.WriteHelp("==============");

d.WriteHelp("> db.info", "Get database informations");
d.WriteHelp("> dump", "Display dump database information");
}
}
}
}
28 changes: 28 additions & 0 deletions LiteDB.Shell/Commands/Open.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace LiteDB.Shell.Commands
{
internal class Open : ConsoleCommand
{
public override bool IsCommand(StringScanner s)
{
return s.Scan(@"open\s+").Length > 0;
}

public override void Execute(LiteShell shell, StringScanner s, Display display, InputCommand input)
{
var filename = s.Scan(@".+");

if (shell.Database != null)
{
shell.Database.Dispose();
}

shell.Database = new LiteDatabase(filename);
}
}
}
6 changes: 3 additions & 3 deletions LiteDB.Shell/Commands/Pretty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

namespace LiteDB.Shell.Commands
{
internal class Pretty : IShellCommand
internal class Pretty : ConsoleCommand
{
public bool IsCommand(StringScanner s)
public override bool IsCommand(StringScanner s)
{
return s.Scan(@"pretty\s*").Length > 0;
}

public void Execute(LiteEngine db, StringScanner s, Display display)
public override void Execute(LiteShell shell, StringScanner s, Display display, InputCommand input)
{
display.Pretty = !(s.Scan(@"off\s*").Length > 0);
}
Expand Down
6 changes: 3 additions & 3 deletions LiteDB.Shell/Commands/Quit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

namespace LiteDB.Shell.Commands
{
internal class Quit : IShellCommand
internal class Quit : ConsoleCommand
{
public bool IsCommand(StringScanner s)
public override bool IsCommand(StringScanner s)
{
return s.Match(@"(quit|exit)$");
}

public void Execute(LiteEngine db, StringScanner s, Display display)
public override void Execute(LiteShell shell, StringScanner s, Display display, InputCommand input)
{
Environment.Exit(0);
}
Expand Down
28 changes: 28 additions & 0 deletions LiteDB.Shell/Commands/Run.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

namespace LiteDB.Shell.Commands
{
internal class Run : ConsoleCommand
{
public override bool IsCommand(StringScanner s)
{
return s.Scan(@"run\s+").Length > 0;
}

public override void Execute(LiteShell shell, StringScanner s, Display display, InputCommand input)
{
var filename = s.Scan(@".+").Trim();

foreach (var line in File.ReadAllLines(filename))
{
input.Queue.Enqueue(line);
}
}
}
}
Loading

0 comments on commit cf80c93

Please sign in to comment.