Open heblol opened 11 months ago
They still haven't solved it, did you solve it any other way?
The solution would be this way.
import { IConfig, ModelBuilder, DialectPostgres, } from "sequelize-typescript-generator";
(async () => { const config: IConfig = { connection: { dialect: "postgres", database: "eetlijst-db", host: "localhost", port: 5432, username: "root", password: "PASSWORD", }, metadata: { indices: true, case: "UNDERSCORE", schema: "eetschema", }, output: { clean: true, outDir: "database/pg/models", }, strict: true, };
const dialect = new DialectPostgres();
const builder = new ModelBuilder(config, dialect);
try { await builder.build(); } catch (err) { console.error(err); process.exit(1); } })();
Hi there, I have a suggested improvement to the package.
Problem: I had some trouble using the correct schema in my project. I added the schema inside the connection object (which is a Options object from Sequelize). However, when I added the schema there, it did not generate types! It said it was empty and I actually thought the repo was broken. However, looking inside the source code, I found that I needed to add the schema to the
metadata
object.Also: Adding using npx terminal command with the
-s
or--schema
makes the generation step not look into the schema.npx stg -D mysql -h localhost -p 3306 -d myDatabase -u myUsername -s mySchema -x myPassword --indices --dialect-options-file path/to/dialectOptions.json --case camel --out-dir models --clean
Probably the connection schema field is necessary, but for me, it was really confusing.
Solution:
metadata
objectOutput printed to terminal: As you can see, it looks at the
t.table_schema='public'
and i expectedt.table_schema='eetschema'