TypeScript: CouchDB のデータを作成 (Create)

```ts:couch_create.ts
// ---------------------------------------------------------------
//	couch_create.ts
//
//					Jul/28/2020
//
// ---------------------------------------------------------------
const axios = require('axios')
// ---------------------------------------------------------------
console.error ("*** 開始 ***")
//
const url_collection = "http://localhost:5984/nagano"

const dict_aa = data_prepare_proc ()

axios.delete(url_collection)
	.then(async function (response) {

	await create_proc(url_collection,dict_aa)
	console.error ("*** 終了 ***")
	})
	.catch(function (error) {
	console.log("*** error *** axios.delete ***")
	console.log(error)
	})
	.then(function () {
	console.log ("*** axios.delete *** end ***")
	})

// ---------------------------------------------------------------
function create_proc(url_collection,dict_aa)
{
	axios.put(url_collection,{})
		.then(async function (response) {
		console.log(response.data)

		for (var key in dict_aa)
			{
			await insert_proc (url_collection,key,dict_aa[key])
			}
		})
	.catch(function (error) {
		console.log("*** error *** axios.put ***")
		console.log(error)
		})
	.then(function () {
		console.log ("*** axios.put *** end ***")
		})
}

// ---------------------------------------------------------------
function insert_proc(url_collection,key,value)
{
	const url = url_collection + "/" + key

	axios.put(url,value)
		.then(function (response) {
//		console.log(response.data)
		})
	.catch(function (error) {
		console.log("*** error *** axios.put ***")
		console.log(error)
		})
	.then(function () {
//		console.log ("*** axios.put *** end ***")
		})

}

// ---------------------------------------------------------------
function data_prepare_proc ()
{
	var dict_aa = new Object ()

	dict_aa = dict_append_proc (dict_aa,'t2021','長野',35496,'2012-7-12')
	dict_aa = dict_append_proc (dict_aa,'t2022','松本',93728,'2012-2-15')
	dict_aa = dict_append_proc (dict_aa,'t2023','上田',74156,'2012-11-2')
	dict_aa = dict_append_proc (dict_aa,'t2024','小諸',38124,'2012-5-22')
	dict_aa = dict_append_proc (dict_aa,'t2025','岡谷',42357,'2012-9-14')
	dict_aa = dict_append_proc (dict_aa,'t2026','塩尻',67283,'2012-8-12')
	dict_aa = dict_append_proc (dict_aa,'t2027','茅野',36251,'2012-3-21')
	dict_aa = dict_append_proc (dict_aa,'t2028','飯田',54623,'2012-7-26')
	dict_aa = dict_append_proc (dict_aa,'t2029','中野',21847,'2012-10-2')
	dict_aa = dict_append_proc (dict_aa,'t2030','諏訪',48392,'2012-12-20')
	dict_aa = dict_append_proc (dict_aa,'t2031','駒ヶ根',51875,'2012-2-7')
	dict_aa = dict_append_proc (dict_aa,'t2032','佐久',69234,'2012-5-17')
	dict_aa = dict_append_proc (dict_aa,'t2033','伊那',31897,'2012-6-19')
	dict_aa = dict_append_proc (dict_aa,'t2034','千曲',52718,'2012-8-24')

	return	dict_aa
}	

// ---------------------------------------------------------------
function dict_append_proc (dict_aa,id_in:string,name_in:string,population_in,date_mod_in:string)
{
	var unit_aa:{} = {};
	unit_aa['name'] = name_in;
	unit_aa['population'] = population_in;
	unit_aa['date_mod'] = date_mod_in;

	dict_aa[id_in] = unit_aa;

	return	dict_aa;
}

// ---------------------------------------------------------------
```

実行

```bash
export NODE_PATH=/usr/lib/node_modules
ts-node ./couch_create.ts
```