import { Module, OnModuleInit } from '@nestjs/common';
import { KnexModule } from '@nestjsplus/knex';
import { MigrationConfig } from '@nestjsplus/knex/dist/interfaces/migration-config.interface';
import * as path from 'path';
@Module({
imports: [
KnexModule.forRootAsync({
useFactory: (): MigrationConfig => ({
config: {
client: 'sqlite3',
useNullAsDefault: true,
connection: ':memory:',
},
migrations: {
directory: path.resolve(__dirname, 'migrations'),
},
}),
}),
],
})
export class DatabaseModule implements OnModuleInit {
constructor(private readonly knexService: KnexService) {}
async onModuleInit() {
await this.knexService.client.migrate.latest();
}
}
npm install
должен автоматически подгрузить ВСЕ зависимости, включая зависимости зависимостей (транзитивные зависимости).node_modules становится
черной дырой
const square = n => n ** 2;
// или
const square = n => n * n;
// или
const square = n => Math.pow(n, 2);
arr.forEach((n, i, a) => a[i] = square(n));
// или
arr.splice(0, arr.length, ...arr.map(square));
// или
for (const [ i, n ] of arr.entries()) {
arr[i] = square(n);
}
// или
for (let i = 0; i < arr.length; i++) {
arr[i] = square(arr[i]);
}
data() {
return {
files: myFiles as FileList;
}
}
data(): {
files?: <FileList | null>;
} {
return {
files: undefined,
};
}
interface Data {
files?: <FileList | null>;
}
export default Vue.extend<Data, Methods, Computed, Props>({
data() {
return {
files: undefined
};
}
});
const names = new Set(objects.map(n => n.name));
strings.forEach(n => (names.has(n) || objects.push({ name: n })));
new Set(strings).forEach(function(n) {
if (!this.has(n)) {
objects.push({ name: n });
}
}, new Set(objects.map(n => n.name)));
// или
for (const name of strings) {
if (objects.every(n => n.name !== name)) {
objects[objects.length] = { name };
}
}
// или
objects.splice(0, objects.length, ...strings.reduce(
(acc, n) => acc.set(n, acc.get(n) ?? { name: n }),
new Map(objects.map(n => [ n.name, n ]))
).values());