我在一个应用程序中将Sequelize与Node和JavaScript一起使用。如您所知,当您执行时,sequelize-init它会创建config、migrations、models和seeders文件夹。在models文件夹内,有一个index.js文件(由 cli 生成),它负责从当前文件夹中读取所有模型及其关联:
索引.js
'use strict';
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const sequelize = require('../database/connection');
const db = {};
fs
.readdirSync(__dirname)
.filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(file => {
const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
db[model.name] = model;
}); …Run Code Online (Sandbox Code Playgroud) 我正在学习Threads并Java考虑创建一个简单的堆栈来测试Thread synchronization。这是堆栈类:
public class Stack {
private int counter;
private String[] storage;
public Stack(final int number) {
storage = new String[number];
counter = 0;
}
public synchronized void push(final String msg) {
if(counter == storage.length) {
System.out.println("Counter full");
} else {
storage[counter++] = msg;
}
}
public synchronized String pop() {
if(isEmpty()) {
System.out.println("There is nothing to pop");
return null;
} else {
String lastElement = storage[--counter];
storage[counter] = null;
return lastElement;
}
} …Run Code Online (Sandbox Code Playgroud)