dsql-admin/dsql-app/.local_dist/server/pages/docs/api-reference.json
2024-11-05 12:12:42 +01:00

1 line
16 KiB
JSON
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{"pageProps":{"user":null,"pages":[{"id":8,"title":"Getting Started","slug":"getting-started","level":1,"parent_id":null},{"id":9,"title":"Getting Started","slug":"getting-started","level":2,"parent_id":3},{"id":2,"title":"Quick Start","slug":"quick-start","level":1,"parent_id":null},{"id":3,"title":"GUI Reference","slug":"gui-reference","level":1,"parent_id":null},{"id":4,"title":"API Reference","slug":"api-reference","level":1,"parent_id":null},{"id":10,"title":"Get","slug":"get","level":2,"parent_id":4},{"id":12,"title":"Database Reference","slug":"database-reference","level":1,"parent_id":null},{"id":11,"title":"Post","slug":"post","level":2,"parent_id":4},{"id":13,"title":"Data types","slug":"data-types","level":2,"parent_id":12},{"id":14,"title":"Querying Data","slug":"querying-data","level":2,"parent_id":12},{"id":15,"title":"Upload Media","slug":"upload-media","level":2,"parent_id":3}],"targetPage":{"title":"API Reference","slug":"api-reference","description":"<p>Access data from external sources. Datasquirel is platform-agnostic so all you need is a HTTP request with the right credentials. Our NPM module abstracts this aspect for ease of use when using node.</p>","content":"<h2>Overview</h2><p>All data stored in your databases can be accessed through our integrated API. There are two sets of API keys, each with different scope. If you want to just fetch data use the <strong>Read Only </strong>API key. If you want to have full access to every aspect of your account, use the <strong>Full Access </strong>API key. Learn how to add API keys <a href=\"docs/quick-start\">here</a>.</p><p><br /></p><h2>Getting started</h2><p>After you have your API keys, you can start making calls using our API integration. We have an NPM module for node projects, but you only need a HTTPS client to make the calls.</p><pre class=\"language-markup\">npm install datasquirel</pre><h2><br /></h2><h2>Fetching Data using the <em>get</em> method</h2><p>The get method only retrieves data. It cannot be used to write or update data. It was created to be the fastest way to access your data, that explains the key length. You can get data using the npm module or via any HTTP request.</p><ul><li>Using CURL:<br /><br /><pre class=\"language-markup\">CURL \n https://datasquirel.com/api/query/get?db=db_name&amp;query=SELECT+*+FROM+table_name \n-H \n \"Authorization:READ_ONLY_API_KEY\";Content-Type:application/json</pre></li><li>Using node module<br /><br /><pre class=\"language-javascript\"><span class=\"token keyword\">const</span> datasquirel <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"datasquirel\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\ndatasquirel\n <span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n <span class=\"token literal-property property\">db</span><span class=\"token operator\">:</span> <span class=\"token string\">\"test\"</span><span class=\"token punctuation\">,</span>\n <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> process<span class=\"token punctuation\">.</span>env<span class=\"token punctuation\">.</span><span class=\"token constant\">DATASQUIREL_READ_ONLY_KEY</span><span class=\"token punctuation\">,</span>\n <span class=\"token literal-property property\">query</span><span class=\"token operator\">:</span> <span class=\"token string\">\"SELECT title, slug, body FROM blog_posts\"</span><span class=\"token punctuation\">,</span>\n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=&gt;</span> <span class=\"token punctuation\">{</span>\n console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>response<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></li></ul><p>The response from this method returns a JSON payload with two fields: <strong>success</strong>: which could be either <code style=\"display:inline\">true</code> or <code style=\"display:inline\">false</code>, and <strong>payload: </strong>which is an array of values when the operation is successfull, or anything from <code style=\"display:inline\">null</code> to a string to an object with an error message. This is a sample of a successful response object:</p><pre class=\"language-javascript\"><span class=\"token punctuation\">{</span>\n <span class=\"token literal-property property\">success</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span>\n <span class=\"token literal-property property\">payload</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n <span class=\"token punctuation\">{</span>\n <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n <span class=\"token literal-property property\">title</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">,</span>\n <span class=\"token literal-property property\">slug</span><span class=\"token operator\">:</span> <span class=\"token string\">\"hello-world\"</span><span class=\"token punctuation\">,</span>\n <span class=\"token literal-property property\">body</span><span class=\"token operator\">:</span> <span class=\"token string\">\"This is a test blog post.\"</span><span class=\"token punctuation\">,</span>\n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span></pre><p>A failed response could return any of three results:</p><ul><li>A <code style=\"display:inline\">null</code> payload.<br /><br /><pre class=\"language-javascript\"><span class=\"token punctuation\">{</span>\n <span class=\"token literal-property property\">success</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span>\n <span class=\"token literal-property property\">payload</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span>\n<span class=\"token punctuation\">}</span></pre><br /></li><li>An error string payload<br /><br /><pre class=\"language-javascript\"><span class=\"token punctuation\">{</span>\n <span class=\"token literal-property property\">success</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span>\n <span class=\"token literal-property property\">payload</span><span class=\"token operator\">:</span> <span class=\"token string\">\"ERROR: no such table as 'blog_posts'\"</span>\n<span class=\"token punctuation\">}</span></pre></li><li>An object payload containing an error field<br /><br /><pre class=\"language-javascript\"><span class=\"token punctuation\">{</span>\n <span class=\"token literal-property property\">success</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span>\n <span class=\"token literal-property property\">payload</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">error</span><span class=\"token operator\">:</span> <span class=\"token string\">\"MYSQL ERROR: syntax error in your sql\"</span> <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></pre></li></ul><p>In each case, the success key refurns a value of <code style=\"display:inline\">false</code> , meaning the query failed.</p><p><br /></p><h2>Using the <em>post</em> method</h2><p>The post method contains the full spectrum of CRUD operations. And it works <strong>*only </strong>with the <strong>Full Access </strong>API key. The read only API key will not work for post methods.</p><ul><li>Using CURL<br /><pre class=\"language-markup\">CURL --json\n '{ \n \"database\": \"social_network\",\n \"query\": \"UPDATE users SET name = 'John' WHERE id = 1\"\n }'\n https://datasquirel.com/api/query/post \n-H \n \"Authorization:FULL_ACCESS_API_KEY\"`</pre><br /></li><li>Using our npm module<br /><br /><pre class=\"language-javascript\"><span class=\"token keyword\">const</span> datasquirel <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"datasquirel\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\ndatasquirel\n <span class=\"token punctuation\">.</span><span class=\"token function\">post</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n <span class=\"token literal-property property\">database</span><span class=\"token operator\">:</span> <span class=\"token string\">\"social_network\"</span><span class=\"token punctuation\">,</span>\n <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> process<span class=\"token punctuation\">.</span>env<span class=\"token punctuation\">.</span><span class=\"token constant\">FULL_ACCESS_API_KEY</span><span class=\"token punctuation\">,</span>\n <span class=\"token literal-property property\">query</span><span class=\"token operator\">:</span> <span class=\"token string\">\"UPDATE users SET name = 'John' WHERE id = 1\"</span><span class=\"token punctuation\">,</span>\n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=&gt;</span> <span class=\"token punctuation\">{</span>\n console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>response<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></li></ul><p>The process yeilds simalar results, but with a slight difference: for operations like <strong>insert </strong>and <strong>update</strong>, the <code style=\"display:inline\">success</code> field yeilds <code style=\"display:inline\">true</code> while the <code style=\"display:inline\">payload</code> field yeilds an object containing fields like </p><pre class=\"language-javascript\"><span class=\"token punctuation\">{</span>\n <span class=\"token literal-property property\">success</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span>\n <span class=\"token literal-property property\">payload</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n <span class=\"token literal-property property\">serverStatus</span><span class=\"token operator\">:</span> <span class=\"token number\">37</span><span class=\"token punctuation\">,</span>\n <span class=\"token literal-property property\">affectedRows</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></pre><p>The post method can also take an object as the <code style=\"display:inline\">query</code> instead of a string. Example:</p><pre class=\"language-javascript\"><span class=\"token keyword\">const</span> datasquirel <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"datasquirel\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\ndatasquirel\n <span class=\"token punctuation\">.</span><span class=\"token function\">post</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n <span class=\"token literal-property property\">database</span><span class=\"token operator\">:</span> <span class=\"token string\">\"social_network\"</span><span class=\"token punctuation\">,</span>\n <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> process<span class=\"token punctuation\">.</span>env<span class=\"token punctuation\">.</span><span class=\"token constant\">FULL_ACCESS_API_KEY</span><span class=\"token punctuation\">,</span>\n <span class=\"token literal-property property\">query</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n <span class=\"token literal-property property\">action</span><span class=\"token operator\">:</span> <span class=\"token string\">\"update\"</span><span class=\"token punctuation\">,</span>\n <span class=\"token literal-property property\">table</span><span class=\"token operator\">:</span> <span class=\"token string\">\"users\"</span><span class=\"token punctuation\">,</span>\n <span class=\"token literal-property property\">data</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">\"John\"</span><span class=\"token punctuation\">,</span>\n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n <span class=\"token literal-property property\">identifierColumnName</span><span class=\"token operator\">:</span> <span class=\"token string\">\"id\"</span><span class=\"token punctuation\">,</span>\n <span class=\"token literal-property property\">identifierValue</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=&gt;</span> <span class=\"token punctuation\">{</span>\n console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>response<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre><p>This yields the exact same result as before. Learn more about the post method <a href=\"api-reference/post\">here</a>.</p>"}},"__N_SSG":true}