Compare commits

..

1 Commits

Author SHA1 Message Date
HSIN-CHUAN HUANG be5e385ae0 Update README.md 2021-11-11 08:56:36 +00:00
10 changed files with 36 additions and 73 deletions
+20 -8
View File
@@ -1,6 +1,11 @@
# BioProAPIServer
### Setup pi3 postgresql
### Setup postgresql
##### Installation
```
sudo apt-get install postgresql libpq-dev postgresql-client postgresql-client-common
```
##### Switch to the Postgres user to configure the database
```
@@ -14,11 +19,18 @@ createuser biopro -P --interactive
##### Postgres command (type psql first to connect postgres)
```
#Enter postgresql
psql
#Find databases
\l
#Find tables
\dt
# Create new database and table if you need
create database test
test=> create table people (name text, company text)
```
### Run apiServer on device
@@ -39,11 +51,11 @@ change the code following as:
change apiserver port to postgres port, 54321 --> 5432 (default)
*/
export const pgDB = {
host: '127.0.0.1', // 服务器地址
port: 54321, // 数据库端口号 -----------------> 5432
username: 'biopro', // 数据库用户名
password: 'BioProControlBox', // 数据库密码
database: 'postgres' // 数据库名称
host: '127.0.0.1',
port: 54321, // -----------------> 5432
username: 'biopro',
password: 'BioProControlBox',
database: 'postgres'
}
```
@@ -67,7 +79,7 @@ nohup node /home/pi/bioproapiserver/dist/app.js > /home/pi/.api_server.out &
##### Localhost test port binding (your device:54321 -> raspberrypi:5432)
```
ssh -NL 54321:localhost:5432 pi@your-pi3-ip
ssh -NL 54321:localhost:5432 pi@your-pi-ip
```
##### Run apiServer on your localhost (remember binding port first)
@@ -79,4 +91,4 @@ npm run start
```
##### References
>https://opensource.com/article/17/10/set-postgres-database-your-raspberry-pi
>https://opensource.com/article/17/10/set-postgres-database-your-raspberry-pi
+1 -1
View File
@@ -25,7 +25,7 @@ export const DB = {
export const pgDB = {
host: '127.0.0.1', // 服务器地址
port: 5432, // 数据库端口号
port: 54321, // 数据库端口号
username: 'biopro', // 数据库用户名
password: 'BioProControlBox', // 数据库密码
database: 'postgres' // 数据库名称
@@ -48,16 +48,6 @@ export const getByParent = async (ctx, next) => {
next()
}
export const getAttrByParent = async (ctx, next) => {
const type = ctx.params.type
const parent = ctx.params.parent
const attr = ctx.params.attr
const result = await recordingDataMeta.getByAttrParent(type, parent, attr)
ctx.body = result
next()
}
export const getCountByParent = async (ctx, next) => {
const type = ctx.params.type
const parent = ctx.params.parent
@@ -61,15 +61,6 @@ export const getByID = async (ctx, next) => {
next()
}
export const getExistOrNotByID = async (ctx, next) => {
const index = ctx.params.channel
const id = ctx.params.id
const result = await recordingDataMini.getExistOrNotByID(id, index)
ctx.body = result
next()
}
export const getByIDs = async (ctx, next) => {
const index = ctx.params.channel
const id = ctx.params.id
+6 -6
View File
@@ -34,12 +34,12 @@ for (let i = 0; i < 32; i++) {
for (let i = 0; i < 32; i++) {
db[i + '_recording_data_minis'] = require('./schema/recording_data_mini.model')(sequelize, Sequelize, i)
}
// for (let i = 256; i < 288; i++) {
// db[i + '_recording_data_raws'] = require('./schema/recording_data_raw.model')(sequelize, Sequelize, i)
// }
// for (let i = 256; i < 288; i++) {
// db[i + '_recording_data_minis'] = require('./schema/recording_data_mini.model')(sequelize, Sequelize, i)
// }
for (let i = 256; i < 288; i++) {
db[i + '_recording_data_raws'] = require('./schema/recording_data_raw.model')(sequelize, Sequelize, i)
}
for (let i = 256; i < 288; i++) {
db[i + '_recording_data_minis'] = require('./schema/recording_data_mini.model')(sequelize, Sequelize, i)
}
db.sequelize.sync()
@@ -43,6 +43,10 @@ module.exports = (sequelize, Sequelize, i) => {
type: Sequelize.TEXT,
defaultValue: ''
},
sd_data: {
type: Sequelize.TEXT,
defaultValue: ''
},
compressed: {
type: Sequelize.BOOLEAN,
defaultValue: false
+1 -22
View File
@@ -98,28 +98,7 @@ class RecordingDataMeta {
return ret
}
async getByAttrParent(type, parent, attr) {
const attrList = attr.split('-')
const collectionType = type + '::jsonb'
const parentOp = {}
parentOp[collectionType] = {
[Op.contains]: '[' + parent + ']'
}
const ret = await db.recording_data_metas.findAll(
{
where: {
parent: parentOp
},
attributes: attrList,
order: [
['id', 'DESC']
],
}
)
return ret
}
async getCountByParent(type, parent) {
async getCountByParent (type, parent) {
const collectionType = type + '::jsonb'
const parentOp = {}
parentOp[collectionType] = {
+2 -13
View File
@@ -31,11 +31,11 @@ class RecordingDataMini {
return ret
}
async clearDeleted (index, where = { deleted: true }) {
async clearDeleted (index) {
const ret = await db[index + '_recording_data_minis'].destroy(
{
where: {
...where
deleted: true
}
}
)
@@ -69,17 +69,6 @@ class RecordingDataMini {
return ret
}
async getExistOrNotByID (id, index) {
const ret = await db[index + '_recording_data_minis'].findOne(
{
where: {
id: id
}
}
).then(token => !(token.data_mean === ''))
return ret
}
async getByIDs (id, index) {
const _id = JSON.parse('[' + id + ']')
const ret = await db[index + '_recording_data_minis'].findAllWithStream(
+2 -2
View File
@@ -37,11 +37,11 @@ class RecordingDataRaw {
return ret
}
async clearDeleted (index, where = { deleted: true }) {
async clearDeleted (index) {
const ret = await db[index + '_recording_data_raws'].destroy(
{
where: {
...where
deleted: true
}
}
)
-2
View File
@@ -39,7 +39,6 @@ export default router
.get('/api/file/meta/get_by_id/:id', controllers.recordingDataMeta.getByID)
.get('/api/file/meta/get_by_path/:path', controllers.recordingDataMeta.getByPath)
.get('/api/file/meta/get_by_parent/:type/:parent', controllers.recordingDataMeta.getByParent)
.get('/api/file/meta/get_attr_by_parent/:type/:parent/:attr', controllers.recordingDataMeta.getAttrByParent)
.get('/api/file/meta/get_count_by_parent/:type/:parent', controllers.recordingDataMeta.getCountByParent)
.get('/api/file/meta/get_by_parent_with_limit/:type/:parent/:limit/:offset/:order', controllers.recordingDataMeta.getByParentWithLimit)
.get('/api/file/meta/get_by_attr_parent_with_limit/:type/:parent/:limit/:offset/:order/:attr', controllers.recordingDataMeta.getByAttrsParentWithLimit)
@@ -65,7 +64,6 @@ export default router
.post('/api/file/mini/update/:channel/:id', controllers.recordingDataMini.update)
.get('/api/file/mini/clear_deleted/:channel/:id', controllers.recordingDataMini.clearDeleted)
.get('/api/file/mini/get_by_id/:channel/:id', controllers.recordingDataMini.getByID)
.get('/api/file/mini/get_exist_or_not_by_id/:channel/:id', controllers.recordingDataMini.getExistOrNotByID)
.get('/api/file/mini/get_by_parent/:channel/:parent', controllers.recordingDataMini.getByParent)
.get('/api/file/mini/get_attr_by_id/:channel/:id/:attr', controllers.recordingDataMini.getAttrByID)
.get('/api/file/mini/get_attr_by_parent/:channel/:parent/:attr', controllers.recordingDataMini.getAttrByParent)