Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (typeof val === "string") {
val = val.toLowerCase();
} else {
throw new Error("email must be a string");
}
this.setDataValue("email", val);
}
}
}, {
timestamps: false,
indexes: [
{
name: "DefineOptionsIndexesTest_lower_email",
unique: true,
fields: [
Sequelize.fn("LOWER", Sequelize.col("email"))
]
}
]
} );
//
// Transaction
// ~~~~~~~~~~~~~
//
// https://github.com/sequelize/sequelize/blob/v3.4.1/test/integration/transaction.test.js
//
s.transaction().then( function( t ) {
t.commit();
t.rollback();
protected async find(message: Message, args: string[], authorModel: UserModel): Promise {
const item: Item | null = await Item.findOne({
include: [{
as: 'holders',
model: UserModel,
required: false,
through: { attributes: ['count'] },
where: { id: message.author.id },
}],
where: where(fn('lower', col('name')), args.join(' ').toLowerCase()) as {},
});
if (!item) return message.reply('could not find an item with that name!');
const embed: MessageEmbed = MessageEmbed.common(message, authorModel)
.setAuthor(
`Information about the ${item.type.toLowerCase()} "${titleCase(item.name)}"`,
this.client.user.displayAvatarURL(),
)
.setThumbnail(message.guild.iconURL())
.setDescription(item.description || '\u200b');
for (let [title, value] of Object.entries(item.toJSON())) {
// Don't show price for non buyable items
if ((title === 'price' && value === null)
// Already in the description of the embed.
|| title === 'description') continue;
private async replaceEndForger(height: number, round: number) {
// Gets all "recent" blocks forged exactly at the end of round to find the producer who should be the next one
// to forge in last position (and so to skip next round), sorted by Max height and grouped by generatorPublicKey
const res: any = await this.blocksModel.findAll({
attributes: [
[sequelize.fn('MAX', sequelize.col('height')), 'lastRoundEndHeight'],
'generatorPublicKey',
],
group: 'generatorPublicKey',
order: sequelize.literal('"lastRoundEndHeight" ASC'),
raw: true,
where: {
[Op.and]: [
{
height: {
[Op.gte]:
height -
this.slots.delegates *
this.dposConstants.dposv2.delegatesPoolSize,
[Op.lt]: height,
},
},
MusicLibrary.prototype.searchAlbums = function(sequelizeQueryOptions) {
var self = this;
sequelizeQueryOptions = sequelizeQueryOptions || {};
sequelizeQueryOptions.attributes = sequelizeQueryOptions.attributes || [];
sequelizeQueryOptions.attributes.push(
// It's not clear, but 'DISTINCT' works for 'artist' as well
[Sequelize.fn('DISTINCT', Sequelize.col('album')), 'album'],
'artist',
[Sequelize.literal('(SELECT location FROM AudioMetadata AS innerData WHERE innerData.artist = artist AND innerData.album = album LIMIT 1)'), 'trackLocation'],
[Sequelize.literal('(SELECT year FROM AudioMetadata AS innerData WHERE innerData.artist = artist AND innerData.album = album LIMIT 1)'), 'year'],
// SQLITE specific:
// When we use aggregated function we have to specify 'AudioMetadata' explicitly
// Otherwise we have NOT specify
[Sequelize.literal('(SELECT sum(duration) FROM AudioMetadata AS innerData WHERE innerData.artist = AudioMetadata.artist AND innerData.album = AudioMetadata.album)'), 'duration'],
);
//
return this.query(sequelizeQueryOptions).then(function(records) {
return records.map(function(record) {
return {
artist: record.artist,
album: record.album,
trackLocation: record.dataValues.trackLocation,
public async run(message: GuildMessage, _: string[], { authorModel }: ICommandRunInfo): Promise
{
const [thisMonth, lastHour]: [CommandLog[], CommandLog[]] = await Promise.all([
CommandLog.findAll({
attributes: [[fn('COUNT', col('command_name')), 'count'], ['command_name', 'commandName']],
group: ['commandName'],
order: [['count', 'DESC']],
}),
CommandLog.findAll({
attributes: [[fn('COUNT', col('command_name')), 'count'], ['command_name', 'commandName']],
group: ['commandName'],
order: [['count', 'DESC']],
where: { run: { [Op.gt]: Date.now() - 35e5 } },
}),
]);
let allTimeCount: number = 0;
const thisMonthTop5: string[] = [];
/* eslint-disable-next-line prefer-const */
for (let { dataValues: { count, commandName } } of thisMonth as any)
{
async function getHistoryCount () {
let count
try {
const historyModel = await new HistoryModel()
const data = await historyModel.findOne({
attributes: [[sequelize.fn('COUNT', sequelize.col('id')), 'num']]
})
count = data.dataValues.num
} catch (err) {
debug(err)
count = '未知'
}
return count
}
{ [Sequelize.Op.eq]: null }
]
},
blockNumber: {
[Sequelize.Op.lte]: blockNumber
}
},
attributes: [
[
Sequelize.fn("SUM", Sequelize.col("quantity")),
"totalAssetQuantity"
],
"address",
"assetType",
[
Sequelize.fn("COUNT", Sequelize.col("UTXO.assetType")),
"utxoQuantity"
]
],
order: Sequelize.literal(
`"totalAssetQuantity" DESC, "assetType" DESC`
),
include: [
{
as: "assetScheme",
model: models.AssetScheme
}
],
group: ["UTXO.address", "UTXO.assetType", "assetScheme.assetType"]
}).then(instances =>
instances.map(instance => instance.get({ plain: true }))
);
, findByTitle : function(request, response, next, title){
db.job.findOne({
where: Sequelize.where(Sequelize.fn('lower', Sequelize.col('TITLE')),
Sequelize.fn('lower', title))
, include : includes
}).then(function(job){
if(!job)
response.status(400).json({ message : "errorMessage.job.not.found" });
request.job = job;
next();
}).catch(function(err){
next(err);
});
}
};
const garbageCollection = async () => {
const garbages = await sequelize.rajio.findAll({
where: {
[Op.or]: {
"downloadCount": {
[Op.gte]: Sequelize.col('downloadLimit')
},
"timeLimit": {
[Op.lte]: new Date()
}
},
"deleted": {
[Op.not]: true
}
}
})
garbages.forEach(v => {
v.deleted = true
fs.removeSync(path.resolve(`./data/upload/${v.id}`))
v.save()
})
}