Skip to content

Commit

Permalink
Merge branch 'rob-bson'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/ugar.db.Mongo.pas
  • Loading branch information
snakeice committed Apr 25, 2019
2 parents 41a959d + e63d911 commit c55e921
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/ugar.db.Mongo.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
interface

uses
Grijjy.Bson, System.Generics.Collections, System.JSON, System.SysUtils, ugar.db.mongo.Enum,
ugar.db.mongo.Query;
Grijjy.Bson, System.Generics.Collections, System.JSON, System.SysUtils, ugar.db.Mongo.Enum,
ugar.db.Mongo.Query;

type

IUgarDatabase = interface;
IUgarCollection = interface;

IUgarCursor = interface
['{18813F27-1B41-453C-86FE-E98AFEB3D905}']
function GetEnumerator: TEnumerator<TUgarBsonDocument>;
function ToArray: TArray<TUgarBsonDocument>;
end;

IUgarClient = interface
['{66FF5346-48F6-44E1-A46F-D8B958F06EA0}']
function ListDatabaseNames: TArray<String>;
Expand All @@ -27,6 +33,8 @@ interface
function ListCollections: TArray<TUgarBsonDocument>;

procedure DropCollection(const AName: String);
function RunCommand(const ACommand: string): IUgarCursor; overload;
function RunCommand(const ACommand: TUgarBsonDocument): IUgarCursor; overload;
procedure DropDatabase();

function GetCollection(const AName: String): IUgarCollection;
Expand All @@ -36,38 +44,33 @@ interface
property Name: String read _GetName;
end;

IUgarCursor = interface
['{18813F27-1B41-453C-86FE-E98AFEB3D905}']
function GetEnumerator: TEnumerator<TUgarBsonDocument>;
function ToArray: TArray<TUgarBsonDocument>;
end;

IUgarCollection = interface
['{9822579B-1682-4FAC-81CF-A4B239777812}']
function _GetDatabase: IUgarDatabase;
function _GetName: String;
function InsertOne(const ADocument: TUgarBsonDocument): Boolean; overload;
function InsertOne(const ADocument: TJsonObject): TJSONObject; overload;
function InsertOne(const ADocument: TJsonObject): TJsonObject; overload;
function InsertOne(const ADocument: string): Boolean; overload;

function InsertMany(const ADocuments: array of TUgarBsonDocument; const AOrdered: Boolean = True): Integer; overload;
function InsertMany(const ADocuments: array of TUgarBsonDocument; const AOrdered: Boolean = True): Integer;
overload;
function InsertMany(const ADocuments: array of TJsonObject; const AOrdered: Boolean = True): Integer; overload;
function InsertMany(const ADocuments: array of string; const AOrdered: Boolean = True): Integer; overload;

function InsertMany(const ADocuments: TArray<TUgarBsonDocument>; const AOrdered: Boolean = True): Integer; overload;
function InsertMany(const ADocuments: TArray<TJsonObject>; const AOrdered: Boolean = True): Integer; overload;
function InsertMany(const ADocuments: TArray<string>; const AOrdered: Boolean = True): Integer; overload;

function InsertMany(const ADocuments: TEnumerable<TUgarBsonDocument>; const AOrdered: Boolean = True): Integer; overload;
function InsertMany(const ADocuments: TEnumerable<TUgarBsonDocument>; const AOrdered: Boolean = True)
: Integer; overload;
function InsertMany(const ADocuments: TEnumerable<TJsonObject>; const AOrdered: Boolean = True): Integer; overload;
function InsertMany(const ADocuments: TEnumerable<string>; const AOrdered: Boolean = True): Integer; overload;

function DeleteOne(const AFilter: TUgarFilter): Boolean;

function DeleteMany(const AFilter: TUgarFilter; const AOrdered: Boolean = True): Integer;

function UpdateOne(const AFilter: TUgarFilter; const AUpdate: TUgarUpdate;
const AUpsert: Boolean = False): Boolean;
function UpdateOne(const AFilter: TUgarFilter; const AUpdate: TUgarUpdate; const AUpsert: Boolean = False): Boolean;

function UpdateMany(const AFilter: TUgarFilter; const AUpdate: TUgarUpdate; const AUpsert: Boolean = False;
const AOrdered: Boolean = True): Integer;
Expand All @@ -91,7 +94,7 @@ interface
property Name: String read _GetName;
end;

TUgarDatabaseFunction = reference to function(AName: string): IUgarCollection;
TUgarDatabaseFunction = reference to function(AName: string = '_'): IUgarCollection;

IUgarConnection = Interface
function GetDatabase(ADatabaseName: string): TUgarDatabaseFunction;
Expand Down
18 changes: 18 additions & 0 deletions src/ugar.db.mongo.internals.pas
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ TUgarDatabase = class(TInterfacedObject, IUgarDatabase)
procedure DropCollection(const AName: String);
procedure DropDatabase;
function GetCollection(const AName: String): IUgarCollection;

function RunCommand(const ACommand: string): IUgarCursor; overload;
function RunCommand(const ACommand: TUgarBsonDocument): IUgarCursor; overload;
protected
property Protocol: TUgarMongoProtocol read FProtocol;
property Name: String read FName;
Expand Down Expand Up @@ -218,6 +221,21 @@ function TUgarDatabase.ListCollections: TArray<TUgarBsonDocument>;
Result[LIndex] := LDocs[LIndex].AsBsonDocument;
end;

function TUgarDatabase.RunCommand(const ACommand: TUgarBsonDocument): IUgarCursor;
var
Writer: IUgarBsonWriter;
Reply: IUgarMongoReply;
begin
Reply := FProtocol.OpQuery(FFullCommandCollectionName, [], 0, -1, ACommand.ToBson, nil);
HandleCommandReply(Reply);
Result := TUgarCursor.Create(FProtocol, FName, Reply.Documents, Reply.CursorId);
end;

function TUgarDatabase.RunCommand(const ACommand: string): IUgarCursor;
begin
Result := RunCommand(TgoBsonDocument.Parse(ACommand));
end;

function TUgarDatabase._GetClient: IUgarClient;
begin
Result := FClient;
Expand Down

0 comments on commit c55e921

Please sign in to comment.