├── .gitattributes
├── .gitignore
├── LICENSE
├── README.md
├── RestApi.Belgrade
├── Api
│ ├── RequestHandlerExtension.cs
│ └── TSqlCommandAdapter.cs
├── RestApi.Belgrade.csproj
└── StartUpExtension.cs
├── RestApi.Dapper
├── Api
│ ├── RequestHandlerExtension.cs
│ └── TSqlCommandAdapter.cs
├── RestApi.Dapper.csproj
└── StartUpExtension.cs
├── RestApi
├── Api
│ ├── DAO
│ │ ├── Options.cs
│ │ └── TSqlCommand.cs
│ ├── HttpRequestMessageExtension.cs
│ ├── RequestHandler.cs
│ ├── RestApiController.cs
│ └── VoidRequestHandler.cs
├── JQueryDataTables
│ ├── HttpRequestExtension.cs
│ ├── RequestHandler.cs
│ └── UriParser.cs
├── LICENSE
├── OData
│ ├── Aggregate.cs
│ ├── HttpRequestExtension.cs
│ ├── ODataController.cs
│ ├── ODataTranslator.g4
│ ├── ODataTranslatorParserExtension.cs
│ ├── RequestHandler.cs
│ └── UriParser.cs
├── Properties
│ └── AssemblyInfo.cs
├── README.md
├── RestApi.csproj
├── SQL
│ ├── QueryBuilder.cs
│ ├── QuerySpec.cs
│ ├── SqlCommandExtensions.cs
│ ├── TableSpec.cs
│ └── TableSpecGenerator.cs
└── Util
│ ├── CommonLogAdapter4ExtensionLogging.cs
│ └── StartUp.cs
├── SqlServer.Rest.Api.sln
├── TestApp
├── Controllers
│ ├── DapperRestApiController.cs
│ ├── RestApiController.cs
│ └── SysODataController.cs
├── Program.cs
├── Properties
│ └── launchSettings.json
├── Startup.cs
├── TestApp.csproj
├── TestApp.csproj.user
├── appsettings.json
└── wwwroot
│ ├── agg.html
│ ├── agg.js
│ ├── expand.html
│ ├── expand.js
│ ├── index.html
│ ├── media
│ ├── css
│ │ ├── dataTables.bootstrap.css
│ │ ├── dataTables.bootstrap.min.css
│ │ ├── dataTables.bootstrap4.css
│ │ ├── dataTables.bootstrap4.min.css
│ │ ├── dataTables.foundation.css
│ │ ├── dataTables.foundation.min.css
│ │ ├── dataTables.jqueryui.css
│ │ ├── dataTables.jqueryui.min.css
│ │ ├── dataTables.material.css
│ │ ├── dataTables.material.min.css
│ │ ├── dataTables.semanticui.css
│ │ ├── dataTables.semanticui.min.css
│ │ ├── dataTables.uikit.css
│ │ ├── dataTables.uikit.min.css
│ │ ├── jquery.dataTables.css
│ │ ├── jquery.dataTables.min.css
│ │ └── jquery.dataTables_themeroller.css
│ ├── images
│ │ ├── Sorting icons.psd
│ │ ├── favicon.ico
│ │ ├── sort_asc.png
│ │ ├── sort_asc_disabled.png
│ │ ├── sort_both.png
│ │ ├── sort_desc.png
│ │ └── sort_desc_disabled.png
│ └── js
│ │ ├── dataTables.bootstrap.js
│ │ ├── dataTables.bootstrap.min.js
│ │ ├── dataTables.bootstrap4.js
│ │ ├── dataTables.bootstrap4.min.js
│ │ ├── dataTables.foundation.js
│ │ ├── dataTables.foundation.min.js
│ │ ├── dataTables.jqueryui.js
│ │ ├── dataTables.jqueryui.min.js
│ │ ├── dataTables.material.js
│ │ ├── dataTables.material.min.js
│ │ ├── dataTables.semanticui.js
│ │ ├── dataTables.semanticui.min.js
│ │ ├── dataTables.uikit.js
│ │ ├── dataTables.uikit.min.js
│ │ ├── jquery.dataTables.js
│ │ ├── jquery.dataTables.min.js
│ │ └── jquery.js
│ ├── objects.html
│ ├── objects.js
│ ├── qunit-parameterize.js
│ ├── table.html
│ ├── table.js
│ └── tests.js
├── TestFunction
├── .gitignore
├── ODataChunked.cs
├── ODataResult.cs
├── TestFunction.csproj
└── host.json
└── doc
├── odata-min-metadata.md
└── odata.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto-detect text files
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.user
2 | .vs/
3 | .vscode/
4 | packages/
5 | nuget/
6 | bin/
7 | obj/
8 | *.log
9 | *.pubxml
10 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | [The "BSD license"]
2 | Copyright (c) 2017, Dr Jovan Popovic
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without
6 | modification, are permitted provided that the following conditions
7 | are met:
8 |
9 | 1. Redistributions of source code must retain the above copyright
10 | notice, this list of conditions and the following disclaimer.
11 | 2. Redistributions in binary form must reproduce the above copyright
12 | notice, this list of conditions and the following disclaimer in the
13 | documentation and/or other materials provided with the distribution.
14 | 3. Neither the name of the copyright holder nor the names of its
15 | contributors may be used to endorse or promote products derived from
16 | this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
19 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------
/RestApi.Belgrade/Api/RequestHandlerExtension.cs:
--------------------------------------------------------------------------------
1 | using Belgrade.SqlClient;
2 | using Belgrade.SqlClient.SqlDb;
3 | using Microsoft.AspNetCore.Mvc;
4 | using RestApi.Belgrade.Api;
5 | using System.Threading.Tasks;
6 |
7 | namespace TSql.RestApi
8 | {
9 | public static class BgRequestHandlerExtension
10 | {
11 | public static Task Process(this RequestHandler rh, ICommand cmd)
12 | {
13 | var pipe = new TSqlCommandAdapter(cmd);
14 | return rh.Process(pipe);
15 | }
16 |
17 | ///
18 | /// Process the current request and returns result using the target database.
19 | ///
20 | /// Connection string to the target database where results will be fetched.
21 | /// Async task that will stream results.
22 | public static Task Process(this RequestHandler rh, string connection)
23 | {
24 | var pipe = new QueryPipe(connection);
25 | var pipeAdapter = new TSqlCommandAdapter(pipe);
26 | return rh.Process(pipeAdapter);
27 | }
28 |
29 | ///
30 | /// Returns results from RequestHandler
as single string.
31 | ///
32 | /// Connection string to the target database where results will be fetched.
33 | /// Async tatsk with ActionResult contianing the results.
34 | public static Task GetResultString(this RequestHandler rh, string connection)
35 | {
36 | var pipe = new QueryPipe(connection);
37 | var pipeAdapter = new TSqlCommandAdapter(pipe);
38 | return rh.GetResult(pipeAdapter);
39 | }
40 |
41 | ///
42 | /// Returns text from RequestHandler
as single string.
43 | ///
44 | /// Connection string to the target database where results will be fetched.
45 | /// Async tatsk with ActionResult contianing the results.
46 | public static Task GetString(this RequestHandler rh, string connection)
47 | {
48 | var pipe = new QueryPipe(connection);
49 | var pipeAdapter = new TSqlCommandAdapter(pipe);
50 | return rh.GetString(pipeAdapter);
51 | }
52 |
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/RestApi.Belgrade/Api/TSqlCommandAdapter.cs:
--------------------------------------------------------------------------------
1 | using Belgrade.SqlClient;
2 | using System;
3 | using System.Data.Common;
4 | using System.Data.SqlClient;
5 | using System.IO;
6 | using System.Threading.Tasks;
7 | using TSql.RestApi;
8 | using BSC = Belgrade.SqlClient;
9 |
10 | namespace RestApi.Belgrade.Api
11 | {
12 | public class TSqlCommandAdapter : TSqlCommand
13 | {
14 | public TSqlCommandAdapter(BSC.ICommand cmd)
15 | {
16 | this.cmd = cmd;
17 | this.pipe = cmd;
18 | }
19 |
20 | public TSqlCommandAdapter(BSC.IQueryPipe pipe)
21 | {
22 | this.pipe = pipe;
23 | }
24 |
25 | public BSC.ICommand cmd { get; }
26 | public BSC.IQueryPipe pipe { get; }
27 |
28 | public override async Task GetString(string defaultOnNoResult = "") {
29 |
30 | MemoryStream stream = new MemoryStream();
31 | await this.pipe.Stream(stream, defaultOnNoResult);
32 | return System.Text.Encoding.UTF8.GetString(stream.ToArray());
33 | }
34 |
35 | public override TSqlCommand OnError(Action handler)
36 | {
37 | this.pipe.OnError(handler);
38 | return this;
39 | }
40 |
41 | public override TSqlCommand Sql(SqlCommand cmd)
42 | {
43 | this.pipe.Sql(cmd);
44 | return this;
45 | }
46 |
47 | public override Task Stream(Stream output, string defaultOnNoResult)
48 | {
49 | return this.pipe.Stream(output, defaultOnNoResult);
50 | }
51 |
52 | public override Task Stream(Stream body, TSql.RestApi.Options options)
53 | {
54 | return this.pipe.Stream(body, options: new BSC.Options() {
55 | Prefix = options.Prefix,
56 | Suffix = options.Suffix,
57 | DefaultOutput = options.DefaultOutput
58 | // @@TODO: Encoding????
59 | });
60 | }
61 |
62 | public override Task Stream(StringWriter output, string defaultOnNoResult)
63 | {
64 | return this.pipe.Stream(output, defaultOnNoResult);
65 | }
66 |
67 |
68 | public override TSqlCommand Param(string name, object value)
69 | {
70 | this.cmd.Param(name, value);
71 | return this;
72 | }
73 |
74 |
75 | public override Task Execute(Action handler)
76 | {
77 | return this.cmd.Map(handler);
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/RestApi.Belgrade/RestApi.Belgrade.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0;netcoreapp2.0;netcoreapp2.1;netcoreapp3.0;netcoreapp3.1
5 | true
6 | true
7 | Jovan Popovic
8 | Belgrade.TSql.RestApi
9 | Belgrade.TSql.RestApi
10 | Apache-2.0
11 | Jovan Popovic
12 | https://github.com/JocaPC/sql-server-rest-api
13 | https://github.com/JocaPC/sql-server-rest-api
14 | Rest API, SQL, TSQL, SQL Server, Azure SQL, OData, JQuery Data Table
15 | 0.9.5
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/RestApi.Dapper/Api/RequestHandlerExtension.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Mvc;
2 | using System.Data.SqlClient;
3 | using System.Threading.Tasks;
4 | using RestApi.Dapper.Api;
5 | using System;
6 |
7 | namespace TSql.RestApi
8 | {
9 | public static class DapperRequestHandlerExtension
10 | {
11 | public static Task Process(this RequestHandler rh, SqlConnection conn)
12 | {
13 | var pipe = new TSqlCommandAdapter(conn);
14 | return rh.Process(pipe);
15 | }
16 |
17 | ///
18 | /// Process the current request and returns result using the target database.
19 | ///
20 | /// Connection string to the target database where results will be fetched.
21 | /// Async task that will stream results.
22 | public static Task Process(this RequestHandler rh, string connection)
23 | {
24 | var pipeAdapter = new TSqlCommandAdapter(new SqlConnection(connection));
25 | return rh.Process(pipeAdapter);
26 | }
27 |
28 | ///
29 | /// Returns results from RequestHandler
as single string.
30 | ///
31 | /// Connection string to the target database where results will be fetched.
32 | /// Async tatsk with ActionResult contianing the results.
33 | public static Task GetResultString(this RequestHandler rh, string connection)
34 | {
35 | var pipeAdapter = new TSqlCommandAdapter(new SqlConnection(connection));
36 | return rh.GetResult(pipeAdapter);
37 | }
38 |
39 | }
40 | }
41 |
42 |
43 | namespace MsSql.RestApi
44 | {
45 | using TSql.RestApi;
46 |
47 | [Obsolete("Use TSql.RestApi namespace")]
48 | public static class DapperRequestHandlerExtension
49 | {
50 | [Obsolete("Use TSql.RestApi namespace")]
51 | public static Task Process(this RequestHandler rh, SqlConnection conn)
52 | {
53 | return TSql.RestApi.DapperRequestHandlerExtension.Process(rh, conn);
54 | }
55 |
56 | ///
57 | /// Process the current request and returns result using the target database.
58 | ///
59 | /// Connection string to the target database where results will be fetched.
60 | /// Async task that will stream results.
61 | [Obsolete("Use TSql.RestApi namespace")]
62 | public static Task Process(this RequestHandler rh, string connection)
63 | {
64 | return TSql.RestApi.DapperRequestHandlerExtension.Process(rh, connection);
65 | }
66 |
67 | ///
68 | /// Returns results from RequestHandler
as single string.
69 | ///
70 | /// Connection string to the target database where results will be fetched.
71 | /// Async tatsk with ActionResult contianing the results.
72 | [Obsolete("Use TSql.RestApi namespace")]
73 | public static Task GetResultString(this RequestHandler rh, string connection)
74 | {
75 | return TSql.RestApi.DapperRequestHandlerExtension.GetResultString(rh, connection);
76 | }
77 | }
78 | }
--------------------------------------------------------------------------------
/RestApi.Dapper/Api/TSqlCommandAdapter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 | using System.Data.Common;
5 | using System.Data.SqlClient;
6 | using System.IO;
7 | using System.Threading.Tasks;
8 | using Dapper;
9 | using TSql.RestApi;
10 |
11 | namespace RestApi.Dapper.Api
12 | {
13 | public class TSqlCommandAdapter : TSqlCommand
14 | {
15 | public TSqlCommandAdapter(SqlConnection connection)
16 | {
17 | this.connection = connection;
18 | }
19 |
20 | public TSqlCommandAdapter(string connection)
21 | {
22 | this.connection = new SqlConnection(connection);
23 | }
24 |
25 | public SqlConnection connection { get; }
26 | public string SqlText { get; private set; }
27 |
28 | public DynamicParameters parameters;
29 |
30 | public override Task GetString(string defaultOnNoResult = "")
31 | {
32 | return this.connection.ExecuteScalarAsync(this.SqlText, param: this.parameters);
33 | }
34 |
35 | public override TSqlCommand OnError(Action handler)
36 | {
37 | return this;
38 | //throw new NotImplementedException("Built-in error handling is not implemented in Dapper RestApi");
39 | }
40 |
41 | static readonly Dictionary typeMap = new Dictionary()
42 | {
43 | { SqlDbType.VarChar, DbType.String },
44 | { SqlDbType.NVarChar, DbType.String },
45 | { SqlDbType.Text, DbType.String },
46 | { SqlDbType.NText, DbType.String },
47 | { SqlDbType.Char, DbType.String },
48 | { SqlDbType.NChar, DbType.String },
49 | { SqlDbType.TinyInt, DbType.Byte },
50 | { SqlDbType.SmallInt, DbType.Int16 },
51 | { SqlDbType.Int, DbType.Int32 },
52 | { SqlDbType.BigInt, DbType.Int64 },
53 | { SqlDbType.Image, DbType.Binary },
54 | { SqlDbType.Bit, DbType.Boolean },
55 | { SqlDbType.Binary, DbType.Binary },
56 | { SqlDbType.VarBinary, DbType.Binary },
57 | { SqlDbType.SmallMoney, DbType.Currency },
58 | { SqlDbType.Money, DbType.Currency },
59 | { SqlDbType.Decimal, DbType.Decimal },
60 | { SqlDbType.Real, DbType.Single },
61 | { SqlDbType.Float, DbType.Double },
62 | { SqlDbType.SmallDateTime, DbType.DateTime },
63 | { SqlDbType.Time, DbType.Time },
64 | { SqlDbType.DateTime, DbType.DateTime },
65 | { SqlDbType.DateTime2, DbType.DateTime2 },
66 | { SqlDbType.Date, DbType.Date },
67 | { SqlDbType.DateTimeOffset, DbType.DateTimeOffset },
68 | { SqlDbType.Timestamp, DbType.Binary },
69 | { SqlDbType.UniqueIdentifier, DbType.Guid }
70 | };
71 |
72 | public override TSqlCommand Sql(SqlCommand cmd)
73 | {
74 | this.SqlText = cmd.CommandText;
75 |
76 | if(this.parameters == null)
77 | this.parameters = new DynamicParameters();
78 | for (int i = 0; i < cmd.Parameters.Count; i++) {
79 | var p = cmd.Parameters[i];
80 | parameters.Add(p.ParameterName, p.Value, dbType: typeMap[p.SqlDbType], size: p.Size, direction: p.Direction);
81 | }
82 |
83 | return this;
84 | }
85 |
86 | public override Task Stream(Stream output, string defaultOnNoResult)
87 | {
88 | return this.connection.QueryAsyncInto(output, this.SqlText, param: this.parameters, defaultOutput: defaultOnNoResult);
89 | }
90 |
91 | public override Task Stream(Stream body, Options options)
92 | {
93 | var dso = new DapperStreamOptions() {
94 | Prefix = options.Prefix,
95 | DefaultOutput = options.DefaultOutput,
96 | Suffix = options.Suffix
97 | };
98 | return this.connection.QueryAsyncInto(body, this.SqlText, dso, param: this.parameters);
99 | }
100 |
101 | public override Task Stream(StringWriter output, string defaultOnNoResult)
102 | {
103 | throw new NotImplementedException("Stream(StringWriter) is not supported in Dapper implementation");
104 | }
105 |
106 | public override Task Execute(Action handler)
107 | {
108 | return this.connection.ExecuteAsync(this.SqlText, param: this.parameters);
109 | }
110 |
111 | public override TSqlCommand Param(string name, object value)
112 | {
113 | this.parameters.Add(name, value);
114 | return this;
115 | }
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/RestApi.Dapper/RestApi.Dapper.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0;netcoreapp2.0;netcoreapp2.1;netcoreapp3.0;netcoreapp3.1
5 | Dapper.TSql.RestApi
6 | 0.8.6
7 | Jovan Popovic
8 | Jovan Popovic
9 | Dapper.TSql.RestApi
10 | Apache-2.0
11 | https://github.com/JocaPC/sql-server-rest-api
12 | https://github.com/JocaPC/sql-server-rest-api
13 | REST API, OData, SQL Server, Azure SQL, Dapper ORM
14 | true
15 | true
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/RestApi.Dapper/StartUpExtension.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Jovan Popovic. All Rights Reserved.
2 | // Licensed under the BSD License. See LICENSE.txt in the project root for license information.
3 |
4 | using Microsoft.Extensions.DependencyInjection;
5 | using TSql.RestApi;
6 | using RestApi.Dapper.Api;
7 | using System;
8 | using System.Data;
9 | using System.Data.SqlClient;
10 |
11 | namespace TSql.RestApi
12 | {
13 | public static class StartUpExtension
14 | {
15 | public static IServiceCollection AddDapperSqlConnection(this IServiceCollection services,
16 | string ConnString, Action