PouchDB のサンプル

// —————————————————————
var text_manipulate = require(‘/var/www/data_base/common/node_common/text_manipulate’)
// —————————————————————
console.error (“*** 開始 ***”)

var PouchDB = require(‘pouchdb’);

var db = new PouchDB(‘db_cities’);

/*
db.info().then(function (info) {
console.log(info);
})
*/

var dict_aa = data_prepare_proc ()

for (var key in dict_aa)
{
const unit_aa = dict_aa[key]
var doc = {“_id”: key, “name”: unit_aa[‘name’],
“population”: unit_aa[‘population’],
“date_mod”: unit_aa[‘date_mod’]}
db.put (doc)
}

const array = [“t2021″,”t2022″,”t2023″,”t2024″,”t2025″,”t2026”]

for (var it in array)
{
const key = array[it]

db.get(key).then(function (doc) {
var str_out = doc._id + “\t” + doc.name + “\t” + doc.population
str_out += “\t” + doc.date_mod
console.log (str_out)
})
}

console.error (“*** 終了 ***”)

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

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

return dict_aa
}

// —————————————————————

SQLAlchemyでMariaDB を使う

#! /usr/bin/python
#-*- coding: utf-8 -*-
#
# sqlalchemy_mariadb.py
#
# Mar/09/2017
#
# ——————————————————————
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
import sys
import datetime

# ——————————————————————
sys.stderr.write (“*** 開始 ***\n”)

metadata = MetaData()

engine = create_engine(‘mysql+mysqlconnector://scott:tiger@localhost/city’)
db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))
Base = declarative_base()
Base.query = db_session.query_property()

#テーブルクラス
class City (Base):
__tablename__ = ‘cities’
id = Column(‘id’, String (64), primary_key=True)
name = Column(‘name’, String(64))
population = Column(‘population’, Integer)
date_mod = Column(‘date_mod’, String(64))

def __init__(self, id, name, population, date_mod):
self.id = id
self.name = name
self.population = population
self.date_mod = date_mod

def __repr__(self):
return ‘City’

cur = db_session.query (City).all()

for unit in cur:
str_out = unit.id + “\t” + unit.name + “\t”
str_out += str (unit.population) + “\t” + unit.date_mod
print (str_out)
#
sys.stderr.write (“*** 終了 ***\n”)
# ——————————————————————

Raspbian にphp7.0 をインストール

参考にしたページ
https://www.symfony.fi/entry/install-php-7-on-raspbian-raspberry-pi

手順

/etc/apt/sources.list に追加
deb http://repozytorium.mati75.eu/raspbian jessie-backports main contrib non-free

# gpg –keyserver pgpkeys.mit.edu –recv-key CCD91D6111A06851
# gpg –armor –export CCD91D6111A06851 | apt-key add –

# apt install php7.0
# apt install php7.0-fpm
# apt install php7.0-mysql
# apt install php7.0-curl