dsql-admin/dsql-app/.local_dist/server/pages/docs/api-reference/post.json
Benjamin Toby 7a06e83a46 Updates
2024-12-08 20:56:57 +01:00

1 line
12 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":"Post","slug":"post","description":"<p>Full CRUD operations on your database using our feature-rich API integration.</p>","content":"<h2>Overview</h2><p>The <code style=\"display:inline\">post</code>  method expands on the <code style=\"display:inline\">get</code> method. It adds the ability to insert, update, and delete data, as well as add and delete images from your static files directories.</p><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><h3>Using CURL<br /></h3><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><p><br /></p><h3>Using our npm module<br /></h3><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><h2><br /></h2><h2>The Response</h2><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><br /></p><h2>Post with object <em>query</em></h2><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.</p><p><br /></p><h2>Adding media</h2><p>In addition to the full CRUD operations the <code style=\"display:inline\">post</code> method offers, you can also add media to your static files directory. This uses the same post method, but with sligtly different parameters. Also, the media you send <strong>*must </strong>be in <code style=\"display:inline\">base64</code> format. You can use our npm client module to convert images and documents to <code style=\"display:inline\">base64</code> format.</p><h3>Using our node module</h3><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<span class=\"token punctuation\">.</span>media\n <span class=\"token punctuation\">.</span><span class=\"token function\">uploadImage</span><span class=\"token punctuation\">(</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_FULL_ACCESS_API_KEY</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\">imageData</span><span class=\"token operator\">:</span> <span class=\"token string\">\"--------- LONG BASE64 STRING ---------\"</span><span class=\"token punctuation\">,</span>\n <span class=\"token literal-property property\">imageName</span><span class=\"token operator\">:</span> <span class=\"token string\">\"sunflower\"</span><span class=\"token punctuation\">,</span>\n <span class=\"token literal-property property\">folder</span><span class=\"token operator\">:</span> <span class=\"token string\">\"flowers\"</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// Optional</span>\n <span class=\"token literal-property property\">mimeType</span><span class=\"token operator\">:</span> <span class=\"token string\">\"jpeg\"</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// Optional</span>\n <span class=\"token literal-property property\">thumbnailSize</span><span class=\"token operator\">:</span> <span class=\"token number\">300</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// Optional</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>"}},"__N_SSG":true}