mySQL SELECT upcoming birthdays

To get all birthdays in next 7 days, add the year difference between the date of birth and today to the date of birth and then find if it falls within next seven days. SELECT * FROM persons WHERE DATE_ADD(birthday, INTERVAL YEAR(CURDATE())-YEAR(birthday) + IF(DAYOFYEAR(CURDATE()) > DAYOFYEAR(birthday),1,0) YEAR) BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 7 DAY); If … Read more

Create unique autoincrement field with mongoose [duplicate]

const ModelIncrementSchema = new Schema({ model: { type: String, required: true, index: { unique: true } }, idx: { type: Number, default: 0 } }); ModelIncrementSchema.statics.getNextId = async function(modelName, callback) { let incr = await this.findOne({ model: modelName }); if (!incr) incr = await new this({ model: modelName }).save(); incr.idx++; incr.save(); return incr.idx; }; const … Read more

How to recover just deleted rows in mysql?

There is another solution, if you have binary logs active on your server you can use mysqlbinlog generate a sql file with it mysqlbinlog binary_log_file > query_log.sql then search for your missing rows. If you don’t have it active, no other solution. Make backups next time.

When to close db connection on android? Every time after your operation finished or after your app exit

I don’t know of any performance penalties in frequent closing/opening of the database (regardless of its size). I think the answer to this question also depends on what type of application is accessing the database. Do you “re-query” the database a lot? Then it seems rectified to keep it open. Do you fetch different data … Read more

Database – Data Versioning [closed]

I have done various audit schemes over the years and I am currently going to implement something like this: Person ———————————————— ID UINT NOT NULL, PersonID UINT NOT NULL, Name VARCHAR(200) NOT NULL, DOB DATE NOT NULL, Email VARCHAR(100) NOT NULL Person_History ———————————————— ID UINT NOT NULL, PersonID UINT NOT NULL, Name VARCHAR(200) NOT NULL, … Read more