(window.webpackJsonp=window.webpackJsonp||[]).push([[63],{200:function(e,t,a){"use strict";a.r(t),a.d(t,"frontMatter",(function(){return i})),a.d(t,"metadata",(function(){return l})),a.d(t,"rightToc",(function(){return b})),a.d(t,"default",(function(){return s}));var n=a(1),r=a(9),o=(a(0),a(229)),i={id:"sql_console",title:"SQL Console",sidebar_label:"SQL Console"},l={id:"sql_console",title:"SQL Console",description:"## `General Description`",source:"@site/docs/sql_console.md",permalink:"/docs/sql_console",editUrl:"https://github.com/plantanapp/documentation/edit/master/docs/sql_console.md",lastUpdatedBy:"Patrick Anderson",lastUpdatedAt:1620397153,sidebar_label:"SQL Console",sidebar:"someSidebar",previous:{title:"Roles",permalink:"/docs/roles"},next:{title:"Users",permalink:"/docs/users"}},b=[{value:"General Description",id:"general-description",children:[]},{value:"Permissions",id:"permissions",children:[]},{value:"Enabling/Disabling SQL Console",id:"enablingdisabling-sql-console",children:[]},{value:"Using the SQL Console",id:"using-the-sql-console",children:[{value:"Run a Query",id:"run-a-query",children:[]},{value:"Download Results",id:"download-results",children:[]},{value:"Upload a Query",id:"upload-a-query",children:[]},{value:"Save a Query",id:"save-a-query",children:[]},{value:"Load a Saved Query",id:"load-a-saved-query",children:[]}]},{value:"Browsing Your Application Tables",id:"browsing-your-application-tables",children:[]}],c={rightToc:b};function s(e){var t=e.components,a=Object(r.a)(e,["components"]);return Object(o.b)("wrapper",Object(n.a)({},c,a,{components:t,mdxType:"MDXLayout"}),Object(o.b)("h2",{id:"general-description"},Object(o.b)("inlineCode",{parentName:"h2"},"General Description")),Object(o.b)("p",null,"The SQL Console allows the ",Object(o.b)("a",Object(n.a)({parentName:"p"},{href:"/docs/audience#low-code-engineers"}),"Low-Code Engineer")," and ",Object(o.b)("a",Object(n.a)({parentName:"p"},{href:"/docs/audience#citizen-developers"}),"Citizen Developer")," roles to access the database in a quick and easy location. It can be used for preparing and testing SQL statements for tokens, dropdown data sources, grid data sources, and other places where SQL queries are needed. The results of the statement, if any, are shown directly below the query input and may also be exported to Excel, CSV, and JSON. Queries can be saved and are available in a dropdown for anyone with access to the console to run. The console also allows you to see the Tables and Columns that have been created by the Plant an App Entity builder so you can easily see your app\u2019s schema."),Object(o.b)("div",{className:"admonition admonition-note alert alert--secondary"},Object(o.b)("div",Object(n.a)({parentName:"div"},{className:"admonition-heading"}),Object(o.b)("h5",{parentName:"div"},Object(o.b)("span",Object(n.a)({parentName:"h5"},{className:"admonition-icon"}),Object(o.b)("svg",Object(n.a)({parentName:"span"},{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"16",viewBox:"0 0 14 16"}),Object(o.b)("path",Object(n.a)({parentName:"svg"},{fillRule:"evenodd",d:"M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"})))),"note")),Object(o.b)("div",Object(n.a)({parentName:"div"},{className:"admonition-content"}),Object(o.b)("p",{parentName:"div"},Object(o.b)("strong",{parentName:"p"},"The SQL Console is disabled by default.")," As a security precaution, in order to see and use the console, it must first be enabled in Plant an App General Settings from the Configuration page. The user enabling the feature must be in either the Admins or Administrators roles or a SuperUser. See below for more details."))),Object(o.b)("h2",{id:"permissions"},Object(o.b)("inlineCode",{parentName:"h2"},"Permissions")),Object(o.b)("p",null,"When dealing with being able to directly query the application database, security is of great concern. By default the SQL Console is disabled. Once enabled, access to it is limited to specific Roles. Below is a permissions grid that shows which roles can see or use the Console."),Object(o.b)("table",null,Object(o.b)("thead",{parentName:"table"},Object(o.b)("tr",{parentName:"thead"},Object(o.b)("th",Object(n.a)({parentName:"tr"},{align:null}),"Role"),Object(o.b)("th",Object(n.a)({parentName:"tr"},{align:"center"}),"Can Enable"),Object(o.b)("th",Object(n.a)({parentName:"tr"},{align:"center"}),"View"),Object(o.b)("th",Object(n.a)({parentName:"tr"},{align:"center"}),"Run Queries"))),Object(o.b)("tbody",{parentName:"table"},Object(o.b)("tr",{parentName:"tbody"},Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:null}),"Admins"),Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"\u2713"),Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"\u2713"),Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}))),Object(o.b)("tr",{parentName:"tbody"},Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:null}),"Citizen Developers"),Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:"center"})),Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"\u2713"),Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"\u2713")),Object(o.b)("tr",{parentName:"tbody"},Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:null}),"Low-Code Engineer"),Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:"center"})),Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"\u2713"),Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"\u2713")),Object(o.b)("tr",{parentName:"tbody"},Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:null}),"Administrators"),Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"\u2713"),Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"\u2713"),Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"\u2713")),Object(o.b)("tr",{parentName:"tbody"},Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:null}),"Super Users"),Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"\u2713"),Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"\u2713"),Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"\u2713")),Object(o.b)("tr",{parentName:"tbody"},Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:null}),"All other roles"),Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:"center"})),Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:"center"})),Object(o.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}))))),Object(o.b)("h2",{id:"enablingdisabling-sql-console"},Object(o.b)("inlineCode",{parentName:"h2"},"Enabling/Disabling SQL Console")),Object(o.b)("p",null,"To Enable or Disable the SQL Console you must be logged in as a user who has one of the roles with a check in the ",Object(o.b)("strong",{parentName:"p"},"Can Enable")," column in the ",Object(o.b)("a",Object(n.a)({parentName:"p"},{href:"#permissions"}),"grid above"),". Once logged in as a user with the correct permission, follow these steps:"),Object(o.b)("ol",null,Object(o.b)("li",{parentName:"ol"},"Navigate to Plant an App ",Object(o.b)("strong",{parentName:"li"},"Configuration")),Object(o.b)("li",{parentName:"ol"},"Select ",Object(o.b)("strong",{parentName:"li"},"General")," in the left column"),Object(o.b)("li",{parentName:"ol"},"Locate the ",Object(o.b)("strong",{parentName:"li"},"Enable/Disable SQL Console")," toggle button and toggle it on"),Object(o.b)("li",{parentName:"ol"},"Click ",Object(o.b)("strong",{parentName:"li"},"Save")," in the upper right corner of the page"),Object(o.b)("li",{parentName:"ol"},"The page will refresh and SQL Console will now be available in the left column")),Object(o.b)("p",null,"To disable the console, follow the same steps, toggling the button off in step 3."),Object(o.b)("p",null,"The Plant an App built-in role ",Object(o.b)("strong",{parentName:"p"},"Admins"),", since they can enable the feature, can see the console in Plant an App configuration, but they cannot use it as the buttons are disabled for them. The idea is that an admin is responsible for general management of the system, but they aren\u2019t developing an application."),Object(o.b)("div",{className:"admonition admonition-note alert alert--secondary"},Object(o.b)("div",Object(n.a)({parentName:"div"},{className:"admonition-heading"}),Object(o.b)("h5",{parentName:"div"},Object(o.b)("span",Object(n.a)({parentName:"h5"},{className:"admonition-icon"}),Object(o.b)("svg",Object(n.a)({parentName:"span"},{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"16",viewBox:"0 0 14 16"}),Object(o.b)("path",Object(n.a)({parentName:"svg"},{fillRule:"evenodd",d:"M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"})))),"note")),Object(o.b)("div",Object(n.a)({parentName:"div"},{className:"admonition-content"}),Object(o.b)("p",{parentName:"div"},Object(o.b)("strong",{parentName:"p"},"Saved queries are not lost when disabling.")," If the SQL Console is ",Object(o.b)("strong",{parentName:"p"},"Disabled")," after users have saved queries, if it is subsequently ",Object(o.b)("strong",{parentName:"p"},"Enabled"),", the save queries will still be available in the Saved Queries dropdown."))),Object(o.b)("h2",{id:"using-the-sql-console"},Object(o.b)("inlineCode",{parentName:"h2"},"Using the SQL Console")),Object(o.b)("p",null,"To use the SQL Console you must be logged in as a user who has one of the roles with a check in the ",Object(o.b)("strong",{parentName:"p"},"Run Queries")," column in the ",Object(o.b)("a",Object(n.a)({parentName:"p"},{href:"#permissions"}),"grid above"),"."),Object(o.b)("p",null,Object(o.b)("img",Object(n.a)({parentName:"p"},{src:"/img/SQLConsole_preview.png",alt:"SQL Console"}))),Object(o.b)("h3",{id:"run-a-query"},Object(o.b)("inlineCode",{parentName:"h3"},"Run a Query")),Object(o.b)("ol",null,Object(o.b)("li",{parentName:"ol"},"Navigate to Plant an App ",Object(o.b)("strong",{parentName:"li"},"Configuration")),Object(o.b)("li",{parentName:"ol"},"Select ",Object(o.b)("strong",{parentName:"li"},"SQL Console")," in the left column (if you don't see this option, please see ",Object(o.b)("a",Object(n.a)({parentName:"li"},{href:"#enablingdisabling-sql-console"}),"Enabling/Disabling SQL Console")," above)"),Object(o.b)("li",{parentName:"ol"},"Enter a Query in the ",Object(o.b)("strong",{parentName:"li"},"SQL Query")," text box. A simple query to begin with is:",Object(o.b)("pre",{parentName:"li"},Object(o.b)("code",Object(n.a)({parentName:"pre"},{className:"language-sql"}),"SELECT UserID, UserName, FirstName, LastName, Email, DisplayName FROM Users\n"))),Object(o.b)("li",{parentName:"ol"},"Click the ",Object(o.b)("strong",{parentName:"li"},"Run Query")," button below the query text box"),Object(o.b)("li",{parentName:"ol"},"The results, if any, will be shown below.")),Object(o.b)("p",null,"If your query returned any error it will be shown at the bottom of the page in a red box with white text."),Object(o.b)("p",null,Object(o.b)("img",Object(n.a)({parentName:"p"},{src:"/img/QueryErrors.png",alt:"Query Error"}))),Object(o.b)("h3",{id:"download-results"},Object(o.b)("inlineCode",{parentName:"h3"},"Download Results")),Object(o.b)("p",null,"The results of queries can also be downloaded in a file. The user has a choice of ",Object(o.b)("strong",{parentName:"p"},"XLSX")," (MS Excel Open XML Spreadsheet), ",Object(o.b)("strong",{parentName:"p"},"CSV")," (comma-separated values), or ",Object(o.b)("strong",{parentName:"p"},"JSON")," (JavaScript Object Notation). These buttons are located to the right of the Run Query button. The query does not need to be executed first before clicking a file button as it is executed when a file button is clicked. Depending on your browser settings, you will either be prompted whether to open or download the file, or it will be opened or downloaded automatically."),Object(o.b)("h3",{id:"upload-a-query"},Object(o.b)("inlineCode",{parentName:"h3"},"Upload a Query")),Object(o.b)("p",null,"If you use another application such as ",Object(o.b)("strong",{parentName:"p"},"SSMS")," to compose your query, you can save the query to a text file and upload it to the SQL Console using the ",Object(o.b)("strong",{parentName:"p"},"Upload File")," button. As soon as you upload the file, the contents of the file will be loaded into the ",Object(o.b)("strong",{parentName:"p"},"SQL Query")," text box."),Object(o.b)("p",null,"For security reasons, the file must be a .txt file. So if you are copying a file saved as .sql, all you have to do is just convert it to .txt first."),Object(o.b)("h3",{id:"save-a-query"},Object(o.b)("inlineCode",{parentName:"h3"},"Save a Query")),Object(o.b)("p",null,"If the query you have loaded in the ",Object(o.b)("strong",{parentName:"p"},"SQL Query")," text box will be useful again in the future, you can save it. Once saved, a query is available in the ",Object(o.b)("strong",{parentName:"p"},"Saved Queries")," dropdown for all users who have Run Query permission. To save a query follow these steps:"),Object(o.b)("ol",null,Object(o.b)("li",{parentName:"ol"},"Enter a query in the ",Object(o.b)("strong",{parentName:"li"},"SQL Query")," text box either by typing it, uploading it, or loading it from the options available in the ",Object(o.b)("strong",{parentName:"li"},"Saved Queries")," dropdown."),Object(o.b)("li",{parentName:"ol"},"Click the ",Object(o.b)("strong",{parentName:"li"},"Save Query")," button in the upper right corner above the text box."),Object(o.b)("li",{parentName:"ol"},"If this is a query you typed or uploaded, the ",Object(o.b)("strong",{parentName:"li"},"New Query")," option will be selected by default in the pop-up.",Object(o.b)("ul",{parentName:"li"},Object(o.b)("li",{parentName:"ul"},"If you want to update an already saved query, select ",Object(o.b)("strong",{parentName:"li"},"Update Existing Query"),". Then select the query you wish to update from the ",Object(o.b)("strong",{parentName:"li"},"Existing Query")," dropdown."),Object(o.b)("li",{parentName:"ul"},"Otherwise, type the name you wish to assign to the query in the ",Object(o.b)("strong",{parentName:"li"},"Name")," field."))),Object(o.b)("li",{parentName:"ol"},"If this is a query that was loaded from the ",Object(o.b)("strong",{parentName:"li"},"Saved Queries")," dropdown, the ",Object(o.b)("strong",{parentName:"li"},"Update Existing Query")," option will be selected by default and the query name will already be loaded in the ",Object(o.b)("strong",{parentName:"li"},"Existing Query")," dropdown.",Object(o.b)("ul",{parentName:"li"},Object(o.b)("li",{parentName:"ul"},"If you have made edits to the query and want to save it as a new query, select the ",Object(o.b)("strong",{parentName:"li"},"New Query")," option and enter a name for it in the ",Object(o.b)("strong",{parentName:"li"},"Name")," field."),Object(o.b)("li",{parentName:"ul"},"Otherwise, you can just click ",Object(o.b)("strong",{parentName:"li"},"Save")," to save your changes and replace the previously saved query.")))),Object(o.b)("h3",{id:"load-a-saved-query"},Object(o.b)("inlineCode",{parentName:"h3"},"Load a Saved Query")),Object(o.b)("p",null,"If you or any other user has saved queries in the ",Object(o.b)("strong",{parentName:"p"},"SQL Console"),", they will be available in the ",Object(o.b)("strong",{parentName:"p"},"Saved Queries")," dropdown. Simply select the query from the dropdown and it will be loaded automatically in the ",Object(o.b)("strong",{parentName:"p"},"SQL Query")," text box. Then all you need to do is click ",Object(o.b)("strong",{parentName:"p"},"Run Query")," or one of the file download options."),Object(o.b)("h2",{id:"browsing-your-application-tables"},Object(o.b)("inlineCode",{parentName:"h2"},"Browsing Your Application Tables")),Object(o.b)("p",null,"The ",Object(o.b)("strong",{parentName:"p"},"SQL Console")," also allows you to view your application tables. These are the tables associated with Plant an App built-in Entities and tables that were created by the Entity builder. These also include the relation tables created when a ",Object(o.b)("strong",{parentName:"p"},Object(o.b)("a",Object(n.a)({parentName:"strong"},{href:"/docs/entities#list-of-entities"}),"List of Entities"))," property relation is configured between two Entities."),Object(o.b)("p",null,"Under the ",Object(o.b)("strong",{parentName:"p"},"Available Entities")," heading on the right side of the page, you will see all your application tables listed. This listing has the following features:"),Object(o.b)("ol",null,Object(o.b)("li",{parentName:"ol"},"Click the ",Object(o.b)("strong",{parentName:"li"},"Plus")," symbol next to any table name to expand it and see the column names and data types for each Entity property."),Object(o.b)("li",{parentName:"ol"},"Click any node of the tree to copy that value to your clipboard to help with precision and speeding up the process of creating queries.")),Object(o.b)("div",{className:"admonition admonition-note alert alert--secondary"},Object(o.b)("div",Object(n.a)({parentName:"div"},{className:"admonition-heading"}),Object(o.b)("h5",{parentName:"div"},Object(o.b)("span",Object(n.a)({parentName:"h5"},{className:"admonition-icon"}),Object(o.b)("svg",Object(n.a)({parentName:"span"},{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"16",viewBox:"0 0 14 16"}),Object(o.b)("path",Object(n.a)({parentName:"svg"},{fillRule:"evenodd",d:"M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"})))),"note")),Object(o.b)("div",Object(n.a)({parentName:"div"},{className:"admonition-content"}),Object(o.b)("p",{parentName:"div"},"Relation tables can be identified by their longer names that follow this naming convention:",Object(o.b)("br",{parentName:"p"}),"\n",Object(o.b)("strong",{parentName:"p"},"app.","[ParentEntitySingularName][ChildEntitySingularName]","[ParentEntityRelationProperty]"),Object(o.b)("br",{parentName:"p"}),"\n","When expanding a relation table, you will see two columns that follow this naming convention:",Object(o.b)("br",{parentName:"p"}),"\n",Object(o.b)("strong",{parentName:"p"},"[ParentEntitySingularName]","Id")," and ",Object(o.b)("strong",{parentName:"p"},"[ChildEntitySingularName]","Id")))))}s.isMDXComponent=!0},229:function(e,t,a){"use strict";a.d(t,"a",(function(){return p})),a.d(t,"b",(function(){return m}));var n=a(0),r=a.n(n);function o(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function i(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function l(e){for(var t=1;t=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}var c=r.a.createContext({}),s=function(e){var t=r.a.useContext(c),a=t;return e&&(a="function"==typeof e?e(t):l({},t,{},e)),a},p=function(e){var t=s(e.components);return r.a.createElement(c.Provider,{value:t},e.children)},d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.a.createElement(r.a.Fragment,{},t)}},u=Object(n.forwardRef)((function(e,t){var a=e.components,n=e.mdxType,o=e.originalType,i=e.parentName,c=b(e,["components","mdxType","originalType","parentName"]),p=s(a),u=n,m=p["".concat(i,".").concat(u)]||p[u]||d[u]||o;return a?r.a.createElement(m,l({ref:t},c,{components:a})):r.a.createElement(m,l({ref:t},c))}));function m(e,t){var a=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var o=a.length,i=new Array(o);i[0]=u;var l={};for(var b in t)hasOwnProperty.call(t,b)&&(l[b]=t[b]);l.originalType=e,l.mdxType="string"==typeof e?e:n,i[1]=l;for(var c=2;c