-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ask the way to inject sql.js when creating new connections on Express.js #522
Comments
I just solved the problem by directly copying the import express from 'express';
import {createConnection} from 'typeorm';
import routes from './routes';
import {errorHandler} from './error/ErrorHandler';
import redis from "redis";
import {Logger} from "tslog";
const cors = require('cors');
// redis setting
const port = 6379;
const host = "localhost";
const password = "changeme";
const redisClient = redis.createClient(port, host);
redisClient.auth(password);
const app = express();
const initSqlJs = require('sql.js');
const getSQL = async() => {
const SQL = await initSqlJs({
// Required to load the wasm binary asynchronously. Of course, you can host it wherever you want
// You can omit locateFile completely when running in node
locateFile: file => `https://sql.js.org/dist/${file}`
});
return new SQL.Database();
}
console.log(getSQL())
// CORS 미들웨어 사용
app.use(cors());
// Request body를 parsing 하기 위한 미들웨어 사용
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// routes 폴더로 분기
app.use(routes);
app.use(errorHandler);
const log: Logger = new Logger({ name: "딜리버블 백엔드 짱짱" });
createConnection({
type: "sqljs",
location: "./sql-wasm.wasm",
autoSave: true,
entities: [
"../entity/**/*.ts"
],
logging: ['query', 'schema'],
synchronize: true
}).then(async (connection) => {
// await insertScriptData(connection);
// const user = await MockUserToFavorite(connection);
// await insertNewsData(connection);
app.listen(8080, () => {
log.info('Server is running on port 8080');
});
});
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried this to create new connection to sql.js by using the code below on
index.ts
However, the error was thrown like the following:
I already tried the following options but it was failed; the method of readFile does not expect two arguments.
#517
What should I do? Thanks for in advance.
The text was updated successfully, but these errors were encountered: