NoSQL (generally interpreted as "Not only SQL") is a rough taxonomy that refers to database management systems other than relational database management systems (RDBMS). Many NoSQL database management systems are highly optimized for data storage and retrieval. Some have minimized functionality for that optimization. A key-value database that can store only a "value" and a "key" for retrieving it is a prime example. From the wiki Simply put, the NoSQL database environment is a non-relational, widely distributed database system that enables fast, dynamic, and high-speed, dynamic organization and analysis of vast amounts of data of a wide variety of types. Quote This storage service using NoSQL is called NoSQL data store and is provided on Azure.
This is a continuation of Last time. I will explain the Python package for using NoSQL. I will explain a part, but for details [here](https://github.com/yuesan/azure-content-jajp/blob/master/articles/storage/storage-python-how-to-use-table-storage .md)
** Create table ** ** TableService **: Access NoSQL datastore on Azure ** create_table **: Create table
account_name = 'Storage account name'
account_key = 'key(Any of multiple keys is fine)'
table_service = TableService(account_name=account_name, account_key=account_key)
table_service.create_table('mytasks')
** Extract ** ** table_service.query_entities ('table name','','record specification') ** Converted to SQL: ** Select name, category From my tasks; **
tasks = table_service.query_entities('mytasks', '', 'name,category')
for task in tasks:
print(task.name)
print(task.category)
** Insert **
table_service.insert_entity('mytasks', {'PartitionKey':name+category, 'RowKey':name, 'name':name, 'category':category})
replace Replace if present in entity, insert otherwise Specify ** PartitionKey ** and ** RowKey ** for the second and third arguments as well.
task = {'name':YUKI, 'category':Friends}
table_service.insert_or_replace_entity('mytasks', name+category, name, task)
update Records can be updated by specifying ** PartitionKey ** and ** RowKey **
table_service.update_entity('mytasks', partition_key, row_key, {'name': name, 'category':category})
** Delete entity ** If you want to delete an entity, you can delete it by specifying ** PartitionKey ** and ** RowKey **.
table_service.delete_entity('mytasks',name+category,name)
** Delete table **
table_service.delete_table('tasktable')
Last time was slightly modified to add a delete function.
views.py
from django.shortcuts import render
from django.http import HttpRequest
from django.template import RequestContext
from datetime import datetime
from django.http import HttpResponse
from django.template.loader import render_to_string
from azure.storage.table import TableService, Entity
account_name = 'Storage name'
account_key = 'Storage key'
table_service = TableService(account_name=account_name, account_key=account_key)
table_service.create_table('mytasks')
def list_tasks(request):
entities = table_service.query_entities('mytasks', '', 'name,category')
html = render_to_string('app/test.html', {'entities':entities})
return HttpResponse(html)
def add_task(request):
name = request.GET['name']
category = request.GET['category']
table_service.insert_entity('mytasks', {'PartitionKey':name+category, 'RowKey':name, 'name':name, 'category':category})
entities = table_service.query_entities('mytasks', '', 'name,category')
html = render_to_string('app/test.html', {'entities':entities})
return HttpResponse(html)
def update_task(request):
name = request.GET['name']
category = request.GET['category']
table_service.delete_entity('mytasks',name+category,name)
entities = table_service.query_entities('mytasks', '', 'name,category')
html = render_to_string('app/test.html', {'entities':entities})
return HttpResponse(html)
test.html
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h2>My Tasks</h2> <br>
<table border="1">
<tr>
<td>Name</td>
<td>Category</td>
<td>Check</td>
</tr>
{% for entity in entities %}
<form action="update_task" method="GET">
<tr>
<td>{{entity.name}} <input type="hidden" name='name' value="{{entity.name}}"></td>
<td>{{entity.category}} <input type="hidden" name='category' value="{{entity.category}}"></td>
<td><input type="submit" value="Delete"></td>
</tr>
</form>
{% endfor %}
</table>
<br>
<hr>
<table border="1">
<form action="add_task" method="GET">
<tr>
<td>Name:</td
><td><input type="text" name="name"></input></td>
</tr>
<tr>
<td>Category:</td>
<td><input type="text" name="category"></input></td>
</tr>
<tr>
<td><input type="submit" value="add task"></input></td>
</tr>
</form>
</table>
</body>
</html>
urls.py
urlpatterns = [
url(r'^$', 'app.views.list_tasks'),
url(r'^list_tasks$', 'app.views.list_tasks'),
url(r'^add_task$', 'app.views.add_task'),
url(r'^update_task$', 'app.views.update_task'),
]
Try only the newly implemented delete function Click the delete button to delete the record
** * As far as I actually checked, I can't delete tables and records in the storage on Azure. If you want to delete the table on Azure, you can recreate the storage. However, it is annoying and difficult, so it is recommended to remove it programmatically (using a package). ** **
Right-click on the project and select ** [Publish] **
Select Microsoft Azure Web Apps ** [Publish] **
Create a new app with [New]!
Give any name to ** Web App name ** and ** App service plan ** If there is no ** Resource group **, please create it
Basically, just check, if you want to make detailed settings, select ** [Next] ** There is no problem, so as it is ** [Issue] ** Then, it will be uploaded on Azure
Finally from the portal management screen of Azure [App Service] ➡︎ [Created APP name] ➡︎ [Overview] ➡︎ [URL] If you select, the Django application you created earlier will work! !!