samp-node icon indicating copy to clipboard operation
samp-node copied to clipboard

Sequelize Problem

Open itspitix opened this issue 3 years ago • 1 comments

I have problem with sequelize using samp-node. Sometimes it connects to the database, but sometimes not. I need to start and stop the server like 10 times to manage it to get it work(connect to the database.) I tried moving the sequelize authentication to OnGameModeInit but still same issue. I'm using sequelize-typescript 2.1.3

Photo: https://imgur.com/kB0Ro00

Example code:

mode-init.ts

import { OnGameModeInit } from 'samp-node-lib';
import { sequelize } from '../database/main';

OnGameModeInit(() => {
    console.log('hi.');
    
    sequelize.authenticate().then(() => {
        console.log('Connected to the database!')
    }).then(() => {
        return sequelize.sync();
    }).catch((Error: string) => {
        console.log(Error);
    })
});

database/main.ts

import { Sequelize } from 'sequelize-typescript';
import { Database } from '../helpers/database.enum';

export const sequelize = new Sequelize({
    database: Database.Name,
    dialect: 'mysql',
    username: Database.Username,
    password: Database.Password,
    storage: ':memory:',
    logging: false,
    models: [ ]
})

itspitix avatar Apr 29 '22 12:04 itspitix

I know this isn't a fix but it's worth trying typeorm?

alextwothousand avatar Apr 29 '22 12:04 alextwothousand

May not be a solution, but you can try to place it within the event loop, such as by setTimeout's 0 ms wrap (which, if effective, samp-node may have something to do with garbage collection), or by connecting to the database directly at node entry rather than in game mode callbacks.

dockfries avatar Jan 03 '23 15:01 dockfries

May not be a solution, but you can try to place it within the event loop, such as by setTimeout's 0 ms wrap (which, if effective, samp-node may have something to do with garbage collection), or by connecting to the database directly at node entry rather than in game mode callbacks.

I tried it doesn't work, I guess the problem cuz samp node is 32bit?

itspitix avatar Jan 03 '23 23:01 itspitix

Yes, that's the problem and loading native modules don't work as expected since samp-node doesn't use the same node version as yours This project won't be maintained anymore since there is going to be a new project called omp-node for open.mp only

AmyrAhmady avatar Jan 04 '23 00:01 AmyrAhmady