How to use @fullstack-one/db - 10 common examples

To help you get started, we’ve selected a few @fullstack-one/db examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fullstack-build / fullstack-one / packages / events / dist / index.js View on Github external
return __awaiter(this, void 0, void 0, function* () {
            const env = di_1.Container.get("ENVIRONMENT");
            this.nodeId = env.nodeId;
            this.eventEmitter = new eventemitter2_1.EventEmitter2(this.CONFIG.eventEmitter);
            this.dbClient = di_1.Container.get(db_1.DbAppClient);
            yield this.finishInitialisation();
            // set listeners that were cached during booting, clean cache afterwards
            Object.values(this.listenersCache).forEach((eventListeners) => {
                Object.values(eventListeners).forEach((listener) => {
                    this._on(listener.eventName, listener.options, listener.callback);
                });
            });
            this.listenersCache = {};
            // fire events that were cached during booting, clean cache afterwards
            Object.entries(this.emittersCache).forEach((emitterEntry) => {
                const eventName = emitterEntry[0];
                const eventEmitters = emitterEntry[1];
                Object.values(eventEmitters).forEach((emitter) => {
                    this._emit(eventName, emitter.nodeId, ...emitter.args);
                });
            });
github fullstack-build / fullstack-one / packages / migration / dist / index.js View on Github external
return __awaiter(this, void 0, void 0, function* () {
            // get DB pgClient from DI container
            const dbClient = di_1.Container.get(db_1.DbAppClient).pgClient;
            // check latest version migrated
            let latestVersion = 0;
            try {
                const dbInitVersion = (yield dbClient.query(`SELECT value FROM _meta.info WHERE key = 'version';`)).rows[0];
                if (dbInitVersion != null && dbInitVersion.value != null) {
                    latestVersion = parseInt(dbInitVersion.value, 10);
                    this.logger.debug('migration.db.init.version.detected', latestVersion);
                }
            }
            catch (err) {
                this.logger.info('migration.db.init.not.found');
            }
            // find init scripts to ignore (version lower than the current one)
            const initSqlFolders = [];
            // run through all registered packages
            this.initSqlPaths.map((initSqlPath) => {
github fullstack-build / fullstack-one / packages / schema-builder / dist / db-schema-builder / index.js View on Github external
return __awaiter(this, void 0, void 0, function* () {
            // get DB pgClient from DI container
            const dbAppClient = di_1.Container.get(db_1.DbAppClient);
            const dbClient = dbAppClient.pgClient;
            // check latest version migrated
            let latestVersion = 0;
            try {
                const dbInitVersion = (yield dbClient.query("SELECT value FROM _meta.info WHERE key = 'version';")).rows[0];
                if (dbInitVersion != null && dbInitVersion.value != null) {
                    latestVersion = parseInt(dbInitVersion.value, 10);
                    this.logger.debug("migration.db.init.version.detected", latestVersion);
                }
            }
            catch (err) {
                this.logger.info("migration.db.init.not.found");
            }
            // find init scripts to ignore (version lower than the current one)
            const initSqlFolders = [];
            // run through all registered packages
github fullstack-build / fullstack-one / packages / file-storage / lib / decorators.ts View on Github external
import { createColumnDecoratorFactory } from "@fullstack-one/db";

// tslint:disable-next-line:variable-name
export const Files = createColumnDecoratorFactory({
  getDirective: (inputTypes?: string[]) => {
    const types = getTypes(inputTypes);
    return `@files(types: [${types.map((type) => `"${type}"`).join(",")}])`;
  },
  getColumnOptions: () => ({ type: "jsonb", gqlType: "[BucketFile]", nullable: true }),
  getExtension: (inputTypes: string[]) => {
    const types = getTypes(inputTypes);
    return ["files", types];
  }
});

function getTypes(inputTypes?: string[]): string[] {
  return inputTypes == null ? ["DEFAULT"] : inputTypes;
}
github fullstack-build / fullstack-one / packages / schema-builder / lib / decorators.ts View on Github external
import { createColumnDecoratorFactory } from "@fullstack-one/db";
import { IPermission, IExpressionInput, IMutationViewsByName } from "./gql-schema-builder/interfaces";

interface IOptions {
  name: string;
  params?: TParams;
  gqlType: string;
}

// tslint:disable-next-line:variable-name
export const Computed = createColumnDecoratorFactory({
  getDirective: ({ name, params }) => {
    if (params == null) return `@computed(expression: "${name}")`;
    return `@computed(expression: "${name}", params: ${JSON.stringify(params)})`;
  },
  getColumnOptions: ({ gqlType }) => ({ gqlType })
});

// tslint:disable-next-line:function-name
export function QueryPermissions(readExpressions: IExpressionInput) {
  return (target: object, columnName: string): void => {
    const entityName = target.constructor.name;
    addQueryPermissions(entityName, columnName, readExpressions);
  };
}

interface IMutationPermissions {
github fullstack-build / fullstack-one / packages / schema-builder / lib / decorators / computedColumn.ts View on Github external
import { expressions } from "../gql-schema-builder/expressions/defineExpression";
import { ExpressionCompiler } from "../gql-schema-builder/expressions/ExpressionCompiler";

interface IOptions {
  name: string;
  params?: TParams;
  gqlType: string;
}

interface IObjectLiteral {
  [key: string]: any;
}

const resolveComputedColumnPrefix = "_resolve_computed_";

@EventSubscriber()
export class AfterLoadForComputedColumnsSubscriber implements EntitySubscriberInterface {
  public afterLoad(entity: IObjectLiteral, event: LoadEvent): Promise {
    const resolveComputedFns = getResolveComputedFns(entity);
    const promises = resolveComputedFns.map((fn) => fn(entity, event.connection));
    return Promise.all(promises);
  }
}

function getResolveComputedFns(entity: IObjectLiteral): Array<(entity: IObjectLiteral, connection: Connection) => Promise> {
  return Object.entries(entity.constructor)
    .filter(([key]) => key.startsWith(resolveComputedColumnPrefix))
    .map(([key, value]) => value as (entity: IObjectLiteral) => Promise);
}

// tslint:disable-next-line:function-name
export function Computed(options: IOptions) {
github fullstack-build / fullstack-one / packages / auto-migrate / dist / index.js View on Github external
    __param(4, di_1.Inject((type) => db_1.DbAppClient)),
    __metadata("design:paramtypes", [logger_1.LoggerFactory,
github fullstack-build / fullstack-one / packages / graceful-shutdown / dist / index.js View on Github external
    __param(3, di_1.Inject((type) => db_1.DbAppClient)),
    __param(4, di_1.Inject((type) => db_1.DbGeneralPool)),
github fullstack-build / fullstack-one / packages / schema-builder / dist / db-schema-builder / index.js View on Github external
for (const sql of Object.values(bootSqlStatements)) {
                this.logger.trace("migration.boot.sql.statement", sql);
                yield dbClient.query(sql);
            }
        });
    }
};
DbSchemaBuilder = __decorate([
    di_1.Service(),
    __param(0, di_1.Inject((type) => boot_loader_1.BootLoader)),
    __param(1, di_1.Inject((type) => config_1.Config)),
    __param(2, di_1.Inject((type) => logger_1.LoggerFactory)),
    __param(3, di_1.Inject((type) => db_1.DbAppClient)),
    __metadata("design:paramtypes", [Object, config_1.Config,
        logger_1.LoggerFactory,
        db_1.DbAppClient])
], DbSchemaBuilder);
exports.DbSchemaBuilder = DbSchemaBuilder;
github fullstack-build / fullstack-one / packages / schema-builder / dist / db-schema-builder / fromPg / pgToDbMeta.js View on Github external
    __param(0, di_1.Inject((type) => db_1.DbAppClient)),
    __metadata("design:paramtypes", [Object])