@melchyore/adonis-cache
Version:
Cache package for AdonisJS V5
49 lines (48 loc) • 2.31 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
const standalone_1 = require("@adonisjs/core/build/standalone");
class DynamoDB extends standalone_1.BaseCommand {
constructor() {
super(...arguments);
this.tableName = 'Cache';
}
async run() {
await this.createTable(this.tableName ?? 'Cache');
await this.exit();
}
async createTable(tableName) {
const Cache = this.application.container.use('Adonis/Addons/Cache');
const spinner = this.logger.await(`Creating table ${tableName}`, undefined, undefined);
const table = await Cache.use('dynamodb').store.createTable(tableName);
if (table) {
this.logger.logUpdate(this.logger.colors.green(`The "${tableName}" table has been created on AWS. Open "config/cache.ts" and create/update DynamoDB driver with table name.`));
}
else {
this.logger.logUpdate(this.logger.colors.red(`Could not create "${tableName}" table. Make sure it doesn't already exist or credentials are not wrong.`));
}
spinner.stop();
}
}
DynamoDB.commandName = 'cache:dynamodb';
DynamoDB.description = 'Create a Cache DynamoDB table on AWS';
DynamoDB.settings = {
loadApp: true,
stayAlive: true
};
__decorate([
standalone_1.args.string({
description: 'Table name',
required: false
}),
__metadata("design:type", String)
], DynamoDB.prototype, "tableName", void 0);
exports.default = DynamoDB;