From e5b78ee6c0b074cade317c612993ec6c01b22de1 Mon Sep 17 00:00:00 2001 From: Jovan Popovic Date: Wed, 22 Jun 2016 13:14:40 +0200 Subject: [PATCH 01/10] Node.js REST APi Draft version of NodeJS REST API that uses SQL/JSON functions --- .gitignore | 4 +- README.md | 3 + .../nodejs-express4-rest-api/.gitignore | 5 ++ .../nodejs-express4-rest-api/README.md | 83 +++++++++++++++++ .../todo-app/nodejs-express4-rest-api/app.js | 15 ++++ .../todo-app/nodejs-express4-rest-api/db.js | 69 +++++++++++++++ .../nodejs-express4-rest-api.njsproj | 88 +++++++++++++++++++ .../nodejs-express4-rest-api/package.json | 19 ++++ .../nodejs-express4-rest-api/routes/todo.js | 71 +++++++++++++++ 9 files changed, 356 insertions(+), 1 deletion(-) create mode 100644 samples/features/json/todo-app/nodejs-express4-rest-api/.gitignore create mode 100644 samples/features/json/todo-app/nodejs-express4-rest-api/README.md create mode 100644 samples/features/json/todo-app/nodejs-express4-rest-api/app.js create mode 100644 samples/features/json/todo-app/nodejs-express4-rest-api/db.js create mode 100644 samples/features/json/todo-app/nodejs-express4-rest-api/nodejs-express4-rest-api.njsproj create mode 100644 samples/features/json/todo-app/nodejs-express4-rest-api/package.json create mode 100644 samples/features/json/todo-app/nodejs-express4-rest-api/routes/todo.js diff --git a/.gitignore b/.gitignore index b317c54a..dad48f39 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,6 @@ samples/databases/wide-world-importers/sample-scripts/always-encrypted/PopulateA *.zip samples/features/in-memory/ticket-reservations/packages/CircularGauge.1.0.0/CreatePackageFile.bat samples/features/in-memory/ticket-reservations/TicketReservations/TicketReservations.dbmdl -samples/databases/wide-world-importers/workload-drivers/vehicle-location-insert/MultithreadedInMemoryTableInsert/obj/Release/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs \ No newline at end of file +samples/databases/wide-world-importers/workload-drivers/vehicle-location-insert/MultithreadedInMemoryTableInsert/obj/Release/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs +*.dat +*.sln \ No newline at end of file diff --git a/README.md b/README.md index 7671a409..eb66a452 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,9 @@ To work in GitHub, go to https://github.com/microsoft/sql-server-samples and for Each sample should be in its own folder with a README.md file that follows the [template](README_samples_template.md). Generated files (e.g., .exe or .bacpac) and user configuration settings (e.g., .user) should not be committed to GitHub. +## Code of Conduct +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. + ## License These samples and templates are all licensed under the MIT license. See the license.txt file in the root. diff --git a/samples/features/json/todo-app/nodejs-express4-rest-api/.gitignore b/samples/features/json/todo-app/nodejs-express4-rest-api/.gitignore new file mode 100644 index 00000000..ac5caeaf --- /dev/null +++ b/samples/features/json/todo-app/nodejs-express4-rest-api/.gitignore @@ -0,0 +1,5 @@ +node_modules/* +bin/* +obj/* +*.sln +*.log \ No newline at end of file diff --git a/samples/features/json/todo-app/nodejs-express4-rest-api/README.md b/samples/features/json/todo-app/nodejs-express4-rest-api/README.md new file mode 100644 index 00000000..71e16865 --- /dev/null +++ b/samples/features/json/todo-app/nodejs-express4-rest-api/README.md @@ -0,0 +1,83 @@ +# NodeJS Express4 REST API that uses SQL/JSON functionalites + +This project contains an example implementation of NodeJS REST API with CRUD operations on a simple Todo table. You can learn how to build REST API on the existing database schema using new JSON functionalities that are available in SQL Server 2016 (or higher) and Azure SQL Database. + +### Contents + +[About this sample](#about-this-sample)
+[Before you begin](#before-you-begin)
+[Run this sample](#run-this-sample)
+[Sample details](#sample-details)
+[Disclaimers](#disclaimers)
+[Related links](#related-links)
+ + + +## About this sample + +- **Applies to:** SQL Server 2016 (or higher), Azure SQL Database +- **Key features:** JSON Functions in SQL Server 2016/Azure SQL Database - FOR JSON and OPENJSON +- **Programming Language:** JavaScript (NodeJS) +- **Authors:** Jovan Popovic + + + +## Before you begin + +To run this sample, you need the following prerequisites. + +**Software prerequisites:** + +1. SQL Server 2016 (or higher) or an Azure SQL Database +2. Visual Studio 2015 (or higher) with the NodeJS + +**Azure prerequisites:** + +1. Permission to create an Azure SQL Database + + + +## Run this sample + +1. Navigate to the folder where you have downloaded sample and run **npm install** in command window. This command will install necessary npm packages defined in project.json. + +2. From SQL Server Management Studio or Sql Server Data Tools connect to your SQL Server 2016 or Azure SQL database and execute setup.sql script that will create and populate Todo table in the database. + +3. From Visual Studio, open the **TodoApp.xproj** file from the root directory, + +4. Locate db.js file in the project, change database connection info in createConnection() method to reference your database, and build solution using Ctrl+Shift+B, right-click on project + Build, or Build/Build Solution from menu. + +5. Run sample app using F5 or Ctrl+F5, +4.1. Open /api/Todo Url to get all Todo items as a JSON array, +4.2. Open /api/Todo/1 Url to get details about a single Todo item with id 1, +4.3. Send POST, PUT, PATCH, or DELETE Http requests to update content of Todo table. + + + +## Sample details + +This sample application shows how to create simple REST API service that performs CRUD operations on a simple Todo table. +NodeJS REST API is used to implement REST Service in the example. +Service uses built-in JSON functionalities that are available in SQL Server 2016 and Azure SQL Database. + + + +## Disclaimers +The code included in this sample is not intended demonstrate some general guidances and arhitectural patterns for web development. +It contains minimal code required to create REST API. +You can easily modify this code to fit the architecture of your application. + + + +## Related Links + +For more information, see this [MSDN documentation](https://msdn.microsoft.com/en-us/library/dn921897.aspx). + +## Code of Conduct +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. + +## License +These samples and templates are all licensed under the MIT license. See the license.txt file in the root. + +## Questions +Email questions to: sqlserversamples@microsoft.com. diff --git a/samples/features/json/todo-app/nodejs-express4-rest-api/app.js b/samples/features/json/todo-app/nodejs-express4-rest-api/app.js new file mode 100644 index 00000000..e5392350 --- /dev/null +++ b/samples/features/json/todo-app/nodejs-express4-rest-api/app.js @@ -0,0 +1,15 @@ +var express = require('express'); +var bodyParser = require('body-parser'); + +var app = express(); +app.use(bodyParser.text()); +app.use('/todo', require('./routes/todo')); + +// catch 404 and forward to error handler +app.use(function (req, res, next) { + var err = new Error('Not Found'); + err.status = 404; + next(err); +}); + +module.exports = app; diff --git a/samples/features/json/todo-app/nodejs-express4-rest-api/db.js b/samples/features/json/todo-app/nodejs-express4-rest-api/db.js new file mode 100644 index 00000000..6dae4c28 --- /dev/null +++ b/samples/features/json/todo-app/nodejs-express4-rest-api/db.js @@ -0,0 +1,69 @@ +function createConnection() { + + var config = { + server : "SERVER.database.windows.net", + userName: "USER", + password: "PASSWORD", + // If you're on Azure, you will need this: + options: { encrypt: true, database: 'DATABASE' } + }; + + var Connection = require('tedious').Connection; + var connection = new Connection(config); + + return connection; +} + +function createRequest(query, connection) { + var Request = require('tedious').Request; + var req = + new Request(query, + function (err, rowCount) { + if (err) { + throw err; + } + connection && connection.close(); + }); + + return req; +} + +function stream (query, connection, output, defaultContent) { + + errorHandler = function (ex) { throw ex; }; + var request = query; + if (typeof query == "string") { + request = this.createRequest(query, connection); + } + + var empty = true; + request.on('row', function (columns) { + empty = false; + output.write(columns[0].value); + }); + + request.on('done', function (rowCount, more, rows) { + if (empty) { + output.write(defaultContent); + } + output.end(); + }); + + request.on('doneProc', function (rowCount, more, rows) { + if (empty) { + output.write(defaultContent); + } + output.end(); + }); + + connection.on('connect', function (err) { + if (err) { + throw err; + } + connection.execSql(request); + }); +} + +module.exports.createConnection = createConnection; +module.exports.createRequest = createRequest; +module.exports.stream = stream; \ No newline at end of file diff --git a/samples/features/json/todo-app/nodejs-express4-rest-api/nodejs-express4-rest-api.njsproj b/samples/features/json/todo-app/nodejs-express4-rest-api/nodejs-express4-rest-api.njsproj new file mode 100644 index 00000000..fc034286 --- /dev/null +++ b/samples/features/json/todo-app/nodejs-express4-rest-api/nodejs-express4-rest-api.njsproj @@ -0,0 +1,88 @@ + + + + 11.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + nodejs-express4-rest-api + nodejs-express4-rest-api + todo + + + + Debug + 2.0 + da18f211-dee4-4b4a-8954-4c7505dc769b + . + bin\www + + + . + . + v4.0 + {3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{349c5851-65df-11da-9384-00065b846f21};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD} + ShowAllFiles + 1337 + True + + + true + + + true + + + + + + + + + + + + + + + + + + + + + + + False + True + 0 + / + http://localhost:48022/ + False + True + http://localhost:1337 + False + + + + + + + CurrentPage + True + False + False + False + + + + + + + + + False + False + + + + + \ No newline at end of file diff --git a/samples/features/json/todo-app/nodejs-express4-rest-api/package.json b/samples/features/json/todo-app/nodejs-express4-rest-api/package.json new file mode 100644 index 00000000..1376b6f8 --- /dev/null +++ b/samples/features/json/todo-app/nodejs-express4-rest-api/package.json @@ -0,0 +1,19 @@ +{ + "name": "nodejs-express4-rest-api", + "version": "0.0.0", + "private": true, + "scripts": { + "start": "node ./bin/www" + }, + "description": "nodejs-express4-rest-api", + "author": { + "name": "Jovan Popovic", + "email": "jovanpop@microsoft.com" + }, + "dependencies": { + "body-parser": "^1.15.2", + "debug": "^2.2.0", + "express": "^4.14.0", + "tedious": "^1.14.0" + } +} diff --git a/samples/features/json/todo-app/nodejs-express4-rest-api/routes/todo.js b/samples/features/json/todo-app/nodejs-express4-rest-api/routes/todo.js new file mode 100644 index 00000000..7eb08aa0 --- /dev/null +++ b/samples/features/json/todo-app/nodejs-express4-rest-api/routes/todo.js @@ -0,0 +1,71 @@ +var express = require('express'); +var router = express.Router(); + +var db = require('../db.js'); +var TYPES = require('tedious').TYPES; + +/* GET task listing. */ +router.get('/', function (req, res) { + db.stream("select * from todo for json path", db.createConnection(), res, '[]'); +}); + +/* GET single task. */ +router.get('/:id', function (req, res) { + + var conn = db.createConnection(); + + var request = db.createRequest("select * from todo where id = @id for json path, without_array_wrapper", conn); + request.addParameter('id', TYPES.Int, req.params.id); + db.stream(request, conn, res, '{}'); +}); + +/* POST create task. */ +router.post('/', function (req, res) { + + var connection = db.createConnection(); + var request = db.createRequest("exec createTodo @todo", connection); + + request.addParameter('todo', TYPES.NVarChar, req.body); + + connection.on('connect', function (err) { + if (err) { + throw err; + } + connection.execSql(request); + }); +}); + +/* PUT update task. */ +router.put('/:id', function (req, res) { + + var connection = db.createConnection(); + var request = db.createRequest("exec updateTodo @id, @todo", connection); + + request.addParameter('id', TYPES.Int, req.params.id); + request.addParameter('todo', TYPES.NVarChar, req.body); + + connection.on('connect', function (err) { + if (err) { + throw err; + } + connection.execSql(request); + }); +}); + +/* DELETE single task. */ +router.delete('/:id', function (req, res) { + + var connection = db.createConnection(); + var request = db.createRequest("delete from todo where id = @id", connection); + + request.addParameter('id', TYPES.Int, req.params.id); + + connection.on('connect', function (err) { + if (err) { + throw err; + } + connection.execSql(request); + }); +}); + +module.exports = router; \ No newline at end of file From 62f1c6596978a2056432319efe833d47e138dd45 Mon Sep 17 00:00:00 2001 From: Jovan Popovic Date: Wed, 22 Jun 2016 13:19:47 +0200 Subject: [PATCH 02/10] Added setup script Added setup.sql script that creates table and stored procedures. --- .../nodejs-express4-rest-api/setup/setup.sql | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 samples/features/json/todo-app/nodejs-express4-rest-api/setup/setup.sql diff --git a/samples/features/json/todo-app/nodejs-express4-rest-api/setup/setup.sql b/samples/features/json/todo-app/nodejs-express4-rest-api/setup/setup.sql new file mode 100644 index 00000000..e1ec3315 --- /dev/null +++ b/samples/features/json/todo-app/nodejs-express4-rest-api/setup/setup.sql @@ -0,0 +1,42 @@ +DROP TABLE IF EXISTS Todo +DROP PROCEDURE IF EXISTS createTodo +DROP PROCEDURE IF EXISTS updateTodo +GO + +CREATE TABLE Todo ( + Id int IDENTITY PRIMARY KEY, + Title nvarchar(30) NOT NULL, + Description nvarchar(4000), + Completed bit, + TargetDate datetime2 +) +GO + +INSERT INTO Todo (Title, Description, Completed, TargetDate) +VALUES +('Install SQL Server 2016','Install RTM version of SQL Server 2016', 0, '2016-06-01'), +('Get new samples','Go to github and download new samples', 0, '2016-06-02'), +('Try new samples','Install new Management Studio to try samples', 0, '2016-06-02') + +GO + +create procedure dbo.createTodo(@todo nvarchar(max)) +as begin + insert into Todo + select * + from OPENJSON(@todo) + WITH ( Title nvarchar(30), Description nvarchar(4000), + Completed bit, TargetDate datetime2) +end +GO + +create procedure updateTodo(@id int, @todo nvarchar(max)) +as begin + update Todo + set Title = json.Title, Description = json.Description, + Completed = json.Completed, TargetDate = json.TargetDate + from OPENJSON( @todo ) + WITH( Title nvarchar(30), Description nvarchar(4000), + Completed bit, TargetDate datetime2) AS json + where Id = @id +end From 09786217eeb9ab6540fd226a726f5d3adc0ac1d9 Mon Sep 17 00:00:00 2001 From: Jovan Popovic Date: Wed, 22 Jun 2016 13:31:31 +0200 Subject: [PATCH 03/10] Added missing www file bin/www file was ignored in .gitignore. Added missing file. --- .../json/todo-app/nodejs-express4-rest-api/.gitignore | 2 +- .../json/todo-app/nodejs-express4-rest-api/bin/www | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 samples/features/json/todo-app/nodejs-express4-rest-api/bin/www diff --git a/samples/features/json/todo-app/nodejs-express4-rest-api/.gitignore b/samples/features/json/todo-app/nodejs-express4-rest-api/.gitignore index ac5caeaf..f9d85749 100644 --- a/samples/features/json/todo-app/nodejs-express4-rest-api/.gitignore +++ b/samples/features/json/todo-app/nodejs-express4-rest-api/.gitignore @@ -1,5 +1,5 @@ node_modules/* -bin/* +bin/*.dll obj/* *.sln *.log \ No newline at end of file diff --git a/samples/features/json/todo-app/nodejs-express4-rest-api/bin/www b/samples/features/json/todo-app/nodejs-express4-rest-api/bin/www new file mode 100644 index 00000000..0f63533b --- /dev/null +++ b/samples/features/json/todo-app/nodejs-express4-rest-api/bin/www @@ -0,0 +1,9 @@ +#!/usr/bin/env node +var debug = require('debug')('nodejs_express4_rest_api'); +var app = require('../app'); + +app.set('port', process.env.PORT || 3000); + +var server = app.listen(app.get('port'), function() { + debug('Express server listening on port ' + server.address().port); +}); From 0e46c20b248eb5ae8f318635809eb02a815bd656 Mon Sep 17 00:00:00 2001 From: Jovan Popovic Date: Wed, 22 Jun 2016 14:51:09 +0200 Subject: [PATCH 04/10] Minor fixes in readme.md Added minor corrections in readme.md files --- .../json/todo-app/dotnet-rest-api/README.md | 9 +++-- .../nodejs-express4-rest-api/README.md | 33 ++++++++++++------- .../nodejs-express4-rest-api/setup.bat | 1 + samples/features/readme.md | 4 +++ 4 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 samples/features/json/todo-app/nodejs-express4-rest-api/setup.bat diff --git a/samples/features/json/todo-app/dotnet-rest-api/README.md b/samples/features/json/todo-app/dotnet-rest-api/README.md index 4807bcc9..181938b7 100644 --- a/samples/features/json/todo-app/dotnet-rest-api/README.md +++ b/samples/features/json/todo-app/dotnet-rest-api/README.md @@ -1,4 +1,4 @@ -# ASP.NET Core REST Web API that uses SQL/JSON functionalites +# ASP.NET Core REST Web API that uses SQL/JSON functionalities This project contains an example implementation of ASP.NET Core REST API with CRUD operations on a simple Todo table. You can learn how to build REST API on the existing database schema using new JSON functionalities that are available in SQL Server 2016 (or higher) and Azure SQL Database. @@ -61,7 +61,7 @@ Service uses built-in JSON functionalities that are available in SQL Server 2016 ## Disclaimers -The code included in this sample is not intended demonstrate some general guidances and arhitectural patterns for web development. It contains minimal code required to create REST API, and it does not use some patterns such as Repository. Sample uses built-in ASP.NET Core Dependency Injection mechanism; however, this is not prerequisite. +The code included in this sample is not intended demonstrate some general guidance and architectural patterns for web development. It contains minimal code required to create REST API, and it does not use some patterns such as Repository. Sample uses built-in ASP.NET Core Dependency Injection mechanism; however, this is not prerequisite. You can easily modify this code to fit the architecture of your application. @@ -70,8 +70,11 @@ You can easily modify this code to fit the architecture of your application. For more information, see this [article](http://www.codeproject.com/Articles/1106622/Building-Web-API-REST-services-on-Azure-SQL-Databa). +## Code of Conduct +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. + ## License These samples and templates are all licensed under the MIT license. See the license.txt file in the root. ## Questions -Email questions to: sqlserversamples@microsoft.com. \ No newline at end of file +Email questions to: [sqlserversamples@microsoft.com](mailto: sqlserversamples@microsoft.com). diff --git a/samples/features/json/todo-app/nodejs-express4-rest-api/README.md b/samples/features/json/todo-app/nodejs-express4-rest-api/README.md index 71e16865..46de88c1 100644 --- a/samples/features/json/todo-app/nodejs-express4-rest-api/README.md +++ b/samples/features/json/todo-app/nodejs-express4-rest-api/README.md @@ -1,6 +1,6 @@ -# NodeJS Express4 REST API that uses SQL/JSON functionalites +# NodeJS Express4 REST API that uses SQL/JSON functionalities -This project contains an example implementation of NodeJS REST API with CRUD operations on a simple Todo table. You can learn how to build REST API on the existing database schema using new JSON functionalities that are available in SQL Server 2016 (or higher) and Azure SQL Database. +This project contains an example implementation of NodeJS REST API with CRUD operations on a simple Todo table. You can learn how to build REST API on the existing database schema using NodeJS, Express4, and new JSON functionalities that are available in SQL Server 2016 (or higher) and Azure SQL Database. ### Contents @@ -39,18 +39,23 @@ To run this sample, you need the following prerequisites. ## Run this sample -1. Navigate to the folder where you have downloaded sample and run **npm install** in command window. This command will install necessary npm packages defined in project.json. +1. Navigate to the folder where you have downloaded sample and run **npm install** in command window, or run setup.bat if you are on Windows operating system. This command will install necessary npm packages defined in project.json. -2. From SQL Server Management Studio or Sql Server Data Tools connect to your SQL Server 2016 or Azure SQL database and execute setup.sql script that will create and populate Todo table in the database. +2. From SQL Server Management Studio or SQL Server Data Tools connect to your SQL Server 2016 or Azure SQL database and execute setup.sql script that will create and populate Todo table in the database. 3. From Visual Studio, open the **TodoApp.xproj** file from the root directory, -4. Locate db.js file in the project, change database connection info in createConnection() method to reference your database, and build solution using Ctrl+Shift+B, right-click on project + Build, or Build/Build Solution from menu. +4. Locate db.js file in the project, change database connection info in createConnection() method to reference your database. the following tokens should be replaced: +4.1. SERVERNAME - name of the database server. +4.2. DATABASE - Name of database where Todo table is stored. +4.3. USERNAME - SQL Server login that can access table data and execute stored procedures. +4.4. PASSWORD - Password associated to SQL Server login. -5. Run sample app using F5 or Ctrl+F5, -4.1. Open /api/Todo Url to get all Todo items as a JSON array, -4.2. Open /api/Todo/1 Url to get details about a single Todo item with id 1, -4.3. Send POST, PUT, PATCH, or DELETE Http requests to update content of Todo table. +5. Build project using Ctrl+Shift+B, right-click on project + Build, or Build/Build Solution from menu. + +6. Run sample app using F5 or Ctrl+F5. /todo Url will be opened with a list of all Todo items as a JSON array, +6.1. Open /api/Todo/1 Url to get details about a single Todo item with id 1, +6.2. Send POST, PUT, or DELETE Http requests to update content of Todo table. @@ -58,12 +63,16 @@ To run this sample, you need the following prerequisites. This sample application shows how to create simple REST API service that performs CRUD operations on a simple Todo table. NodeJS REST API is used to implement REST Service in the example. -Service uses built-in JSON functionalities that are available in SQL Server 2016 and Azure SQL Database. +1. app.js file that contains startup code. +2. db.js file that contains functions that wrap Tedious library +3. todo.js file that contains action that will be called on GET, POST, PUT, and DELETE Http requests. + +Service uses Tedious library for data access and built-in JSON functionalities that are available in SQL Server 2016 and Azure SQL Database. ## Disclaimers -The code included in this sample is not intended demonstrate some general guidances and arhitectural patterns for web development. +The code included in this sample is not intended demonstrate some general guidance and architectural patterns for web development. It contains minimal code required to create REST API. You can easily modify this code to fit the architecture of your application. @@ -80,4 +89,4 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope These samples and templates are all licensed under the MIT license. See the license.txt file in the root. ## Questions -Email questions to: sqlserversamples@microsoft.com. +Email questions to: [sqlserversamples@microsoft.com](mailto: sqlserversamples@microsoft.com). \ No newline at end of file diff --git a/samples/features/json/todo-app/nodejs-express4-rest-api/setup.bat b/samples/features/json/todo-app/nodejs-express4-rest-api/setup.bat new file mode 100644 index 00000000..b66c116a --- /dev/null +++ b/samples/features/json/todo-app/nodejs-express4-rest-api/setup.bat @@ -0,0 +1 @@ +npm install \ No newline at end of file diff --git a/samples/features/readme.md b/samples/features/readme.md index ce6c230d..ed91354f 100644 --- a/samples/features/readme.md +++ b/samples/features/readme.md @@ -11,3 +11,7 @@ Master Data Services (MDS) is the SQL Server solution for master data management [R Services](features/r-services) SQL Server R Services brings R processing close to the data, allowing more scalable and more efficient predictive analytics. + +[JSON Support](features/json) + +Built-in JSON functions enable you to easily parse and query JSON data stored in database, transform relational data to JSON text, and vice versa. \ No newline at end of file From 5569b694a6ecd1cb9c453ee8eed4f06f63ef8471 Mon Sep 17 00:00:00 2001 From: Jovan Popovic Date: Wed, 22 Jun 2016 15:14:52 +0200 Subject: [PATCH 05/10] Added readme file in json folder Added missing readme.md file in features/json folder --- samples/features/json/readme.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 samples/features/json/readme.md diff --git a/samples/features/json/readme.md b/samples/features/json/readme.md new file mode 100644 index 00000000..744d1313 --- /dev/null +++ b/samples/features/json/readme.md @@ -0,0 +1,10 @@ +# Samples that use JSON functionalities that are available in SQL Server 2016 (or higher) and Azure SQL Database + +[Todo REST API - ASP.NET Core](todo-app/dotnet-rest-api) + +This project contains an example implementation of ASP.NET Core REST API with CRUD operations on a simple Todo table. You can learn how to build REST API on the existing database schema using new JSON functionalities that are available in SQL Server 2016 (or higher) and Azure SQL Database. + +[Todo REST API - NodeJS/Express4](todo-app/nodejs-express4-rest-api) + +This project contains an example implementation of NodeJS REST API using Express4 framework and Tedious. REST API has basic CRUD operations on a simple Todo table. You can learn how to build REST API on the existing database schema using new JSON functionalities that are available in SQL Server 2016 (or higher) and Azure SQL Database. + From 29cdb0d2c04443ca97aaeb6c3a87e31be811a0d8 Mon Sep 17 00:00:00 2001 From: Jovan Popovic Date: Wed, 22 Jun 2016 15:15:25 +0200 Subject: [PATCH 06/10] Updated setup file Updated setup.sql file in node.js rest api example. --- .../features/json/todo-app/nodejs-express4-rest-api/setup.bat | 1 + 1 file changed, 1 insertion(+) create mode 100644 samples/features/json/todo-app/nodejs-express4-rest-api/setup.bat diff --git a/samples/features/json/todo-app/nodejs-express4-rest-api/setup.bat b/samples/features/json/todo-app/nodejs-express4-rest-api/setup.bat new file mode 100644 index 00000000..b66c116a --- /dev/null +++ b/samples/features/json/todo-app/nodejs-express4-rest-api/setup.bat @@ -0,0 +1 @@ +npm install \ No newline at end of file From b07d18d3119f23ddf960ce74fe055a1dc1f62ce2 Mon Sep 17 00:00:00 2001 From: Jovan Popovic Date: Wed, 22 Jun 2016 15:22:20 +0200 Subject: [PATCH 07/10] Updated links in readme.md file Updated links to features in readme.md file in features folder. --- samples/features/readme.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/features/readme.md b/samples/features/readme.md index ed91354f..fbe48847 100644 --- a/samples/features/readme.md +++ b/samples/features/readme.md @@ -1,17 +1,17 @@ # Samples for specific SQL Server and Azure SQL features -[In-Memory OLTP](features/in-memory) +[In-Memory OLTP](in-memory) In-Memory OLTP can significantly improve performance of transaction processing in SQL Server and Azure SQL Database. It is a memory-optimized database engine integrated into the database engine, optimized for OLTP. With In-Memory OLTP you can increase the transaction throughput by up to 30 times, depending on the specifics of the workload. -[Master Data Services](features/master-data-services) +[Master Data Services](master-data-services) Master Data Services (MDS) is the SQL Server solution for master data management. Master data management (MDM) enables you organization to discover and define non-transactional lists of data, and compile maintainable, reliable master lists. -[R Services](features/r-services) +[R Services](r-services) SQL Server R Services brings R processing close to the data, allowing more scalable and more efficient predictive analytics. -[JSON Support](features/json) +[JSON Support](json) Built-in JSON functions enable you to easily parse and query JSON data stored in database, transform relational data to JSON text, and vice versa. \ No newline at end of file From 92b619fd9b1f334aa5f350633d9c93943f978078 Mon Sep 17 00:00:00 2001 From: Jovan Popovic Date: Wed, 22 Jun 2016 15:27:57 +0200 Subject: [PATCH 08/10] Formatting of nodejs readme.md --- .../nodejs-express4-rest-api/README.md | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/samples/features/json/todo-app/nodejs-express4-rest-api/README.md b/samples/features/json/todo-app/nodejs-express4-rest-api/README.md index 46de88c1..48d4a854 100644 --- a/samples/features/json/todo-app/nodejs-express4-rest-api/README.md +++ b/samples/features/json/todo-app/nodejs-express4-rest-api/README.md @@ -45,11 +45,22 @@ To run this sample, you need the following prerequisites. 3. From Visual Studio, open the **TodoApp.xproj** file from the root directory, -4. Locate db.js file in the project, change database connection info in createConnection() method to reference your database. the following tokens should be replaced: -4.1. SERVERNAME - name of the database server. -4.2. DATABASE - Name of database where Todo table is stored. -4.3. USERNAME - SQL Server login that can access table data and execute stored procedures. -4.4. PASSWORD - Password associated to SQL Server login. +4. Locate db.js file in the project, change database connection info in createConnection() method to reference your database. + +``` + var config = { + server : "SERVER.database.windows.net", + userName: "USER", + password: "PASSWORD", + // If you're on Azure, you will need this: + options: { encrypt: true, database: 'DATABASE' } + }; +``` +The following tokens should be replaced: + 1. SERVERNAME - name of the database server. + 2. DATABASE - Name of database where Todo table is stored. + 3. USERNAME - SQL Server login that can access table data and execute stored procedures. + 4. PASSWORD - Password associated to SQL Server login. 5. Build project using Ctrl+Shift+B, right-click on project + Build, or Build/Build Solution from menu. From f73d1d1bd0fc5b456ce67e46c04a28388b3d912f Mon Sep 17 00:00:00 2001 From: Jovan Popovic Date: Wed, 22 Jun 2016 15:29:48 +0200 Subject: [PATCH 09/10] Revert "Formatting of nodejs readme.md" This reverts commit 92b619fd9b1f334aa5f350633d9c93943f978078. --- .../nodejs-express4-rest-api/README.md | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/samples/features/json/todo-app/nodejs-express4-rest-api/README.md b/samples/features/json/todo-app/nodejs-express4-rest-api/README.md index 48d4a854..46de88c1 100644 --- a/samples/features/json/todo-app/nodejs-express4-rest-api/README.md +++ b/samples/features/json/todo-app/nodejs-express4-rest-api/README.md @@ -45,22 +45,11 @@ To run this sample, you need the following prerequisites. 3. From Visual Studio, open the **TodoApp.xproj** file from the root directory, -4. Locate db.js file in the project, change database connection info in createConnection() method to reference your database. - -``` - var config = { - server : "SERVER.database.windows.net", - userName: "USER", - password: "PASSWORD", - // If you're on Azure, you will need this: - options: { encrypt: true, database: 'DATABASE' } - }; -``` -The following tokens should be replaced: - 1. SERVERNAME - name of the database server. - 2. DATABASE - Name of database where Todo table is stored. - 3. USERNAME - SQL Server login that can access table data and execute stored procedures. - 4. PASSWORD - Password associated to SQL Server login. +4. Locate db.js file in the project, change database connection info in createConnection() method to reference your database. the following tokens should be replaced: +4.1. SERVERNAME - name of the database server. +4.2. DATABASE - Name of database where Todo table is stored. +4.3. USERNAME - SQL Server login that can access table data and execute stored procedures. +4.4. PASSWORD - Password associated to SQL Server login. 5. Build project using Ctrl+Shift+B, right-click on project + Build, or Build/Build Solution from menu. From 6d29a5c0741b458d5f46aee7748b8d7d284f50de Mon Sep 17 00:00:00 2001 From: Jovan Popovic Date: Wed, 22 Jun 2016 15:31:30 +0200 Subject: [PATCH 10/10] Updated readme.md file --- .../nodejs-express4-rest-api/README.md | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/samples/features/json/todo-app/nodejs-express4-rest-api/README.md b/samples/features/json/todo-app/nodejs-express4-rest-api/README.md index 46de88c1..1a848930 100644 --- a/samples/features/json/todo-app/nodejs-express4-rest-api/README.md +++ b/samples/features/json/todo-app/nodejs-express4-rest-api/README.md @@ -46,16 +46,26 @@ To run this sample, you need the following prerequisites. 3. From Visual Studio, open the **TodoApp.xproj** file from the root directory, 4. Locate db.js file in the project, change database connection info in createConnection() method to reference your database. the following tokens should be replaced: -4.1. SERVERNAME - name of the database server. -4.2. DATABASE - Name of database where Todo table is stored. -4.3. USERNAME - SQL Server login that can access table data and execute stored procedures. -4.4. PASSWORD - Password associated to SQL Server login. + 1. SERVERNAME - name of the database server. + 2. DATABASE - Name of database where Todo table is stored. + 3. USERNAME - SQL Server login that can access table data and execute stored procedures. + 4. PASSWORD - Password associated to SQL Server login. + +``` + var config = { + server : "SERVER.database.windows.net", + userName: "USER", + password: "PASSWORD", + // If you're on Azure, you will need this: + options: { encrypt: true, database: 'DATABASE' } + }; +``` 5. Build project using Ctrl+Shift+B, right-click on project + Build, or Build/Build Solution from menu. 6. Run sample app using F5 or Ctrl+F5. /todo Url will be opened with a list of all Todo items as a JSON array, -6.1. Open /api/Todo/1 Url to get details about a single Todo item with id 1, -6.2. Send POST, PUT, or DELETE Http requests to update content of Todo table. + 1. Open /api/Todo/1 Url to get details about a single Todo item with id 1, + 2. Send POST, PUT, or DELETE Http requests to update content of Todo table.