AmyrAhmady/samp-node

Sequelize Problem

itspitix opened this issue · 4 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: [ ]
})

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

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.

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?

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