feat(SPG-10) Research & Testing PG to Couch, Couch to PG
parent
e78d1c90d1
commit
1124307453
|
@ -0,0 +1,17 @@
|
||||||
|
import { ConfigModule } from "@nestjs/config";
|
||||||
|
import { CouchDataController } from "./infrastructure/couch.controller";
|
||||||
|
import { Module } from "@nestjs/common";
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [
|
||||||
|
ConfigModule.forRoot(),
|
||||||
|
// TypeOrmModule.forFeature([UserPrivilegeModel], CONNECTION_NAME.DEFAULT),
|
||||||
|
// CqrsModule,
|
||||||
|
],
|
||||||
|
controllers: [
|
||||||
|
CouchDataController
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
],
|
||||||
|
})
|
||||||
|
export class CouchModule {}
|
|
@ -0,0 +1,66 @@
|
||||||
|
import { Body, Controller, Get, Post } from "@nestjs/common";
|
||||||
|
|
||||||
|
import { ApiTags } from "@nestjs/swagger";
|
||||||
|
import { Unprotected } from "src/core/guards";
|
||||||
|
import * as Nano from 'nano'
|
||||||
|
import { CreateUserPrivilegeDto } from "src/modules/user-related/user-privilege/infrastructure/dto/create-user-privilege.dto";
|
||||||
|
|
||||||
|
@ApiTags(`couch`)
|
||||||
|
@Controller('couch')
|
||||||
|
@Unprotected()
|
||||||
|
export class CouchDataController {
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
async createDoc(
|
||||||
|
@Body() entity: CreateUserPrivilegeDto
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
let n = Nano('http://admin:secret@127.0.0.1:5984')
|
||||||
|
let db = await n.db.create(entity.name)
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error, 'dsa')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('doc')
|
||||||
|
async createDocs(
|
||||||
|
@Body() entity: CreateUserPrivilegeDto
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
const nano = require("nano")("http://admin:secret@127.0.0.1:5984");
|
||||||
|
const people = nano.db.use('string');
|
||||||
|
console.log(await people.info())
|
||||||
|
const data = {
|
||||||
|
id: '1212',
|
||||||
|
name: 'dsadas'
|
||||||
|
}
|
||||||
|
// await people.insert(data)
|
||||||
|
|
||||||
|
people.changesReader.start()
|
||||||
|
.on('change', (change) => { console.log(change) })
|
||||||
|
.on('batch', (b) => {
|
||||||
|
console.log('a batch of', b.length, 'changes has arrived');
|
||||||
|
}).on('seq', (s) => {
|
||||||
|
console.log('sequence token', s);
|
||||||
|
}).on('error', (e) => {
|
||||||
|
console.error('error', e);
|
||||||
|
})
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error, 'dsa')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
async getDoc(
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
let n = Nano('http://admin:secret@127.0.0.1:5984')
|
||||||
|
const people = n.use('string');
|
||||||
|
|
||||||
|
// return people.get();
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error, 'dsa')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue