From cbb98ce579f22d674680a71027bfd2134203a106 Mon Sep 17 00:00:00 2001 From: Jovan Popovic Date: Thu, 13 Apr 2017 17:50:38 +0200 Subject: [PATCH] Fixed scripts in react/nodejs --- .../nodejs-comments-app/setup/demo.sql | 33 +++++++++++++ .../nodejs-comments-app/setup/setup.login.sql | 15 ++++++ .../nodejs-comments-app/setup/setup.sql | 47 +++---------------- 3 files changed, 55 insertions(+), 40 deletions(-) create mode 100644 samples/features/json/reactjs/nodejs-comments-app/setup/demo.sql create mode 100644 samples/features/json/reactjs/nodejs-comments-app/setup/setup.login.sql diff --git a/samples/features/json/reactjs/nodejs-comments-app/setup/demo.sql b/samples/features/json/reactjs/nodejs-comments-app/setup/demo.sql new file mode 100644 index 00000000..b2de6bb4 --- /dev/null +++ b/samples/features/json/reactjs/nodejs-comments-app/setup/demo.sql @@ -0,0 +1,33 @@ +select * +from Comments +for json path + +select * +from Comments +where id = 1 +for json path, without_array_wrapper + +declare @p nvarchar(4000) = N'[{"author":"John","text":"I like it too!"},{"author":"Jane","text":"Thanks!"},{"author":"Jane","text":"Buy :)"}]' + +select * +from openjson(@p) + with ( author nvarchar(20), text nvarchar(200)) + +go + +declare @p nvarchar(4000) = N'[{"author":"John","text":"I like it too!"},{"author":"Jane","text":"Thanks!"},{"author":"Jane","text":"Buy :)"}]' + +insert into Comments(author, text) +select * +from openjson(@p) + with ( author nvarchar(20), text nvarchar(200)) + +select * +from Comments + +select author, count(*) comments +from Comments +group by author +for json path + +delete Comments where id > 2 diff --git a/samples/features/json/reactjs/nodejs-comments-app/setup/setup.login.sql b/samples/features/json/reactjs/nodejs-comments-app/setup/setup.login.sql new file mode 100644 index 00000000..4be39029 --- /dev/null +++ b/samples/features/json/reactjs/nodejs-comments-app/setup/setup.login.sql @@ -0,0 +1,15 @@ +DROP LOGIN WebLogin +CREATE LOGIN WebLogin WITH PASSWORD = 'SQLPass1234!' +GO + +DROP USER IF EXISTS WebUser +CREATE USER WebUser FROM LOGIN WebLogin +GO + +DROP ROLE IF EXISTS WebUserRole +CREATE ROLE WebUserRole +GO + +GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE TO WebUserRole +EXEC sp_addrolemember N'WebUserRole', N'WebUser' +GO \ No newline at end of file diff --git a/samples/features/json/reactjs/nodejs-comments-app/setup/setup.sql b/samples/features/json/reactjs/nodejs-comments-app/setup/setup.sql index f5db1fba..7fbb14cd 100644 --- a/samples/features/json/reactjs/nodejs-comments-app/setup/setup.sql +++ b/samples/features/json/reactjs/nodejs-comments-app/setup/setup.sql @@ -1,47 +1,14 @@ ---CREATE DATABASE TodoDb; ---USE TodoDb; -DROP TABLE IF EXISTS Todo -DROP PROCEDURE IF EXISTS createTodo -DROP PROCEDURE IF EXISTS updateTodo +DROP TABLE IF EXISTS Comments GO -CREATE TABLE Todo ( +CREATE TABLE Comments ( id int IDENTITY PRIMARY KEY, - title nvarchar(30) NOT NULL, - description nvarchar(4000), - completed bit, - dueDate datetime2 default (dateadd(day, 3, getdate())) + author nvarchar(30) NOT NULL, + text nvarchar(4000) ) GO -INSERT INTO Todo (title, description, completed, dueDate) +INSERT INTO Comments (author, text) VALUES -('Install SQL Server 2016','Install RTM version of SQL Server 2016', 0, '2017-03-08'), -('Get new samples','Go to github and download new samples', 0, '2016-03-09'), -('Try new samples','Install new Management Studio to try samples', 0, '2016-03-12') - -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, dueDate 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, dueDate = json.dueDate - from OPENJSON( @todo ) - WITH( title nvarchar(30), description nvarchar(4000), - completed bit, dueDate datetime2) AS json - where id = @id -end -go - -select * from todo for json path \ No newline at end of file +('John','This is great!'), +('Jane','I like the fact that it is simple.') \ No newline at end of file