Skip to content

Commit

Permalink
BasicDatabase 2->1 tpl arg, doc fixs
Browse files Browse the repository at this point in the history
  • Loading branch information
cruisercoder committed Feb 24, 2018
1 parent 25f0291 commit e4284e8
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 88 deletions.
128 changes: 63 additions & 65 deletions src/std/database/BasicDatabase.d
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
module std.database.BasicDatabase;
import std.experimental.logger;
import std.database.exception;
import std.datetime;

import std.typecons;
import std.database.common;
import std.database.pool;
import std.database.resolver;
import std.database.source;

import std.database.allocator;
import std.traits;
import std.container.array;
import std.variant;

import std.range.primitives;
import std.database.option;

/**
BasicDatabase: a common and generic front-end for database access
Expand All @@ -36,11 +17,28 @@ import std.database.option;
with a driver:
---
import std.database;
alias DB = BasicDatabase!(MyDriver!MyPolicy, MyPolicy);
alias DB = BasicDatabase!(MyDriver);
---
*/
module std.database.BasicDatabase;
import std.experimental.logger;
import std.database.exception;
import std.datetime;

import std.typecons;
import std.database.common;
import std.database.pool;
import std.database.resolver;
import std.database.source;

import std.database.allocator;
import std.traits;
import std.container.array;
import std.variant;

import std.range.primitives;
import std.database.option;

public import std.database.array;

Expand Down Expand Up @@ -71,13 +69,13 @@ alias FeatureArray = Feature[];
A root type for interacting with databases. It's primary purpose is act as
a factory for database connections. This type can be shared across threads.
*/
struct BasicDatabase(D,P) {
struct BasicDatabase(D) {
alias Driver = D;
alias Policy = P;
alias Policy = Driver.Policy;
alias Database = Driver.Database;
alias Allocator = Policy.Allocator;
alias Connection = BasicConnection!(Driver,Policy);
alias Cell = BasicCell!(Driver,Policy);
alias Connection = BasicConnection!(Driver);
alias Cell = BasicCell!(Driver);
alias Pool = .Pool!(Driver.Connection);
alias ScopedResource = .ScopedResource!Pool;

Expand Down Expand Up @@ -146,12 +144,12 @@ auto ref driverDatabase() {return data_.database;}
/**
Holds a connection to the database.
*/
struct BasicConnection(D,P) {
struct BasicConnection(D) {
alias Driver = D;
alias Policy = P;
alias Policy = Driver.Policy;
alias DriverConnection = Driver.Connection;
alias Statement = BasicStatement!(Driver,Policy);
alias Database = BasicDatabase!(Driver,Policy);
alias Statement = BasicStatement!(Driver);
alias Database = BasicDatabase!(Driver);
alias Pool = Database.Pool;
alias ScopedResource = Database.ScopedResource;
alias DatabaseImpl = Driver.Database;
Expand Down Expand Up @@ -229,14 +227,14 @@ data_ = Data(&db.data_.refCountedPayload(),uri);
/**
Manages statement details such as query execution and input binding.
*/
struct BasicStatement(D,P) {
struct BasicStatement(D) {
alias Driver = D;
alias Policy = P;
alias Policy = Driver.Policy;
alias DriverStatement = Driver.Statement;
alias Connection = BasicConnection!(Driver,Policy);
alias Result = BasicResult!(Driver,Policy);
alias RowSet = BasicRowSet!(Driver,Policy);
alias ColumnSet = BasicColumnSet!(Driver,Policy);
alias Connection = BasicConnection!(Driver);
alias Result = BasicResult!(Driver);
alias RowSet = BasicRowSet!(Driver);
alias ColumnSet = BasicColumnSet!(Driver);
//alias Allocator = Policy.Allocator;
alias ScopedResource = Connection.ScopedResource;

Expand Down Expand Up @@ -342,12 +340,12 @@ struct BasicStatement(D,P) {
An internal class for result access and iteration. See the RowSet type for range based access
to results
*/
struct BasicResult(D,P) {
struct BasicResult(D) {
alias Driver = D;
alias Policy = P;
alias Policy = Driver.Policy;
alias ResultImpl = Driver.Result;
alias Statement = BasicStatement!(Driver,Policy);
alias RowSet = BasicRowSet!(Driver,Policy);
alias Statement = BasicStatement!(Driver);
alias RowSet = BasicRowSet!(Driver);
//alias Allocator = Driver.Policy.Allocator;
alias Bind = Driver.Bind;
//alias Row = .Row;
Expand Down Expand Up @@ -402,11 +400,11 @@ package:
/**
A range over result column information
*/
struct BasicColumnSet(D,P) {
struct BasicColumnSet(D) {
alias Driver = D;
alias Policy = P;
alias Result = BasicResult!(Driver,Policy);
alias Column = BasicColumn!(Driver,Policy);
alias Policy = Driver.Policy;
alias Result = BasicResult!(Driver);
alias Column = BasicColumn!(Driver);
private Result result_;

this(Result result) {
Expand All @@ -428,10 +426,10 @@ struct BasicColumnSet(D,P) {
}


struct BasicColumn(D,P) {
struct BasicColumn(D) {
alias Driver = D;
alias Policy = P;
alias Result = BasicResult!(Driver,Policy);
alias Policy = Driver.Policy;
alias Result = BasicResult!(Driver);
private Result result_;
private size_t idx_;

Expand All @@ -449,12 +447,12 @@ struct BasicColumn(D,P) {
/**
A input range over the results of a query.
*/
struct BasicRowSet(D,P) {
struct BasicRowSet(D) {
alias Driver = D;
alias Policy = P;
alias Result = BasicResult!(Driver,Policy);
alias Row = BasicRow!(Driver,Policy);
alias ColumnSet = BasicColumnSet!(Driver,Policy);
alias Policy = Driver.Policy;
alias Result = BasicResult!(Driver);
alias Row = BasicRow!(Driver);
alias ColumnSet = BasicColumnSet!(Driver);

void rowSetTag();

Expand Down Expand Up @@ -522,14 +520,14 @@ struct BasicRowSet(D,P) {
/**
A row accessor for the current row in a RowSet input range.
*/
struct BasicRow(D,P) {
struct BasicRow(D) {
alias Driver = D;
alias Policy = P;
alias Result = BasicResult!(Driver,Policy);
alias RowSet = BasicRowSet!(Driver,Policy);
alias Cell = BasicCell!(Driver,Policy);
alias Value = BasicValue!(Driver,Policy);
alias Column = BasicColumn!(Driver,Policy);
alias Policy = Driver.Policy;
alias Result = BasicResult!(Driver);
alias RowSet = BasicRowSet!(Driver);
alias Cell = BasicCell!(Driver);
alias Value = BasicValue!(Driver);
alias Column = BasicColumn!(Driver);

private RowSet rows_;

Expand Down Expand Up @@ -564,12 +562,12 @@ struct BasicRow(D,P) {
/**
A value accessor for an indexed value in the current row in a RowSet input range.
*/
struct BasicValue(D,P) {
struct BasicValue(D) {
alias Driver = D;
alias Policy = P;
alias Policy = Driver.Policy;
//alias Result = Driver.Result;
alias Result = BasicResult!(Driver,Policy);
alias Cell = BasicCell!(Driver,Policy);
alias Result = BasicResult!(Driver);
alias Cell = BasicCell!(Driver);
alias Bind = Driver.Bind;
private Result* result_;
private Bind* bind_;
Expand Down Expand Up @@ -632,10 +630,10 @@ struct EfficientValue(T) {
}


struct BasicCell(D,P) {
struct BasicCell(D) {
alias Driver = D;
alias Policy = P;
alias Result = BasicResult!(Driver,Policy);
alias Policy = Driver.Policy;
alias Result = BasicResult!(Driver);
alias Bind = Driver.Bind;
private Bind* bind_;
private int rowIdx_;
Expand All @@ -656,7 +654,7 @@ struct Converter(D,P) {
alias Policy = P;
alias Result = Driver.Result;
alias Bind = Driver.Bind;
alias Cell = BasicCell!(Driver,Policy);
alias Cell = BasicCell!(Driver);

static Y convert(Y)(Result *r, ref Cell cell) {
ValueType x = cell.bind.type, y = TypeInfo!Y.type;
Expand Down
7 changes: 4 additions & 3 deletions src/std/database/freetds/database.d
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ struct DefaultPolicy {
alias Allocator = MyMallocator;
}

alias Database(T) = BasicDatabase!(Driver!T,T);
alias Database(T) = BasicDatabase!(Driver);

auto createDatabase()(string defaultURI="") {
return Database!DefaultPolicy(defaultURI);
}


struct Driver(Policy) {
struct Driver(P) {
alias Policy = P;
alias Allocator = Policy.Allocator;
alias Cell = BasicCell!(Driver!Policy,Policy);
alias Cell = BasicCell!(Driver);

private static bool isError(RETCODE ret) {
return
Expand Down
11 changes: 6 additions & 5 deletions src/std/database/mysql/database.d
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import std.string;

// alias Database(T) = std.database.impl.Database!(T,DatabaseImpl!T);

alias Database(T) = BasicDatabase!(Driver!T.Sync,T);
alias Database(T) = BasicDatabase!(Driver!T.Sync);

alias AsyncDatabase(T) = BasicDatabase!(Driver!T.Async,T);
alias AsyncDatabase(T) = BasicDatabase!(Driver!T.Async);


struct DefaultPolicy {
Expand Down Expand Up @@ -77,7 +77,8 @@ private static void raiseError()(string msg, MYSQL_STMT* stmt, int ret) {
throw new DatabaseException("mysql error: " ~ msg);
}

private struct Driver(Policy) {
private struct Driver(P) {
alias Policy = P;

struct Describe {
int index;
Expand All @@ -98,7 +99,7 @@ private struct Driver(Policy) {

struct Sync {
alias Allocator = Policy.Allocator;
alias Cell = BasicCell!(Sync,Policy);
alias Cell = BasicCell!(Sync);
alias const(ubyte)* cstring;

alias Describe = Driver!Policy.Describe;
Expand Down Expand Up @@ -436,7 +437,7 @@ private struct Driver(Policy) {
alias Allocator = Policy.Allocator;
alias Describe = Driver!Policy.Describe;
alias Bind = Driver!Policy.Bind;
alias Cell = BasicCell!(Async,Policy);
alias Cell = BasicCell!(Async);

struct Database {
alias queryVariableType = QueryVariableType.QuestionMark;
Expand Down
7 changes: 4 additions & 3 deletions src/std/database/odbc/database.d
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ struct DefaultPolicy {
alias Allocator = MyMallocator;
}

alias Database(T) = BasicDatabase!(Driver!T,T);
alias Database(T) = BasicDatabase!(Driver);

auto createDatabase()(string defaultURI="") {
return Database!DefaultPolicy(defaultURI);
}

struct Driver(Policy) {
struct Driver(P) {
alias Policy = P;
alias Allocator = Policy.Allocator;
alias Cell = BasicCell!(Driver,Policy);
alias Cell = BasicCell!(Driver);

struct Database {
alias queryVariableType = QueryVariableType.QuestionMark;
Expand Down
7 changes: 4 additions & 3 deletions src/std/database/oracle/database.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct DefaultPolicy {
alias Allocator = MyMallocator;
}

alias Database(T) = BasicDatabase!(Driver!T,T);
alias Database(T) = BasicDatabase!(Driver!T);

auto createDatabase()(string defaultURI="") {
return Database!DefaultPolicy(defaultURI);
Expand Down Expand Up @@ -68,9 +68,10 @@ void attrGet(T)(void* handle, ub4 handleType, OCIError* error, ub4 attribute, re



struct Driver(Policy) {
struct Driver(P) {
alias Policy = P;
alias Allocator = Policy.Allocator;
alias Cell = BasicCell!(Driver,Policy);
alias Cell = BasicCell!(Driver);



Expand Down
7 changes: 4 additions & 3 deletions src/std/database/poly/database.d
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import std.database.variant;

import std.meta;

alias Database(T) = BasicDatabase!(Driver!T,T);
alias Database(T) = BasicDatabase!(Driver!T);

struct DefaultPolicy {
alias Allocator = MyMallocator;
Expand All @@ -36,9 +36,10 @@ auto createDatabase()(string defaultURI="") {
return Database!DefaultPolicy(defaultURI);
}

struct Driver(Policy) {
struct Driver(P) {
alias Policy = P;
alias Allocator = Policy.Allocator;
alias Cell = BasicCell!(Driver,Policy);
alias Cell = BasicCell!(Driver);
alias BindArgs = Array!Variant;

// revise using allocator make
Expand Down
7 changes: 4 additions & 3 deletions src/std/database/postgres/database.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct DefaultPolicy {
static const bool nonblocking = false;
}

alias Database(T) = BasicDatabase!(Driver!T,T);
alias Database(T) = BasicDatabase!(Driver!T);

auto createDatabase()(string defaultURI="") {
return Database!DefaultPolicy(defaultURI);
Expand Down Expand Up @@ -64,9 +64,10 @@ int checkForZero()(PGconn *con, string msg, int result) {
return result;
}

struct Driver(Policy) {
struct Driver(P) {
alias Policy = P;
alias Allocator = Policy.Allocator;
alias Cell = BasicCell!(Driver,Policy);
alias Cell = BasicCell!(Driver);

struct Database {
static const auto queryVariableType = QueryVariableType.Dollar;
Expand Down
Loading

0 comments on commit e4284e8

Please sign in to comment.