1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| import dynamoose from "dynamoose"; import { DongleHeartbeatSchema } from "@schemas/dongle"; import { PVSchema } from "@schemas/pv"; import { DynamoDBTableName, getDynamoDBTableName, } from "@albedo-inc/infra-config"; import { ObjectType } from "nestjs-dynamoose"; import { PrismaClient } from "@prisma/client";
const db = new PrismaClient();
const ddb = new dynamoose.aws.ddb.DynamoDB({ credentials: { accessKeyId: "ak", secretAccessKey: "as", }, region: "cn-northwest-1", }); dynamoose.aws.ddb.set(ddb);
const ENV_NAME = "dev"; const sourceDB = { heartbeat: dynamoose.model( DynamoDBTableName.DONGLE_HEARTBEAT_TBL, DongleHeartbeatSchema, { tableName: getDynamoDBTableName( DynamoDBTableName.DONGLE_HEARTBEAT_TBL, ENV_NAME ), } ), pv: dynamoose.model(DynamoDBTableName.PV_TBL, PVSchema, { tableName: getDynamoDBTableName(DynamoDBTableName.PV_TBL, ENV_NAME), }), };
const testPostgresConnnect = async () => { const versionResult = await db.$queryRaw`select version()`; console.log("version: ", versionResult[0].version); };
const exec = async () => { await testPostgresConnnect();
console.log("同步pv"); let lastKey: ObjectType = null; let pvCount = 0; do { let pvItems = await sourceDB.pv.scan().startAt(lastKey).exec(); lastKey = pvItems.lastKey; pvCount += pvItems.count;
} while (lastKey); console.log(`同步pv完成, 同步个数: ${pvCount}`); };
exec() .then(() => { console.log("done"); }) .catch((err) => console.error(err));
|