ehhh
ehhh
TTCTheo's Typesafe Cult
Created by ehhh on 4/28/2023 in #questions
Issues importing a class in the provider folder of AdonisJS while creating TypeScript definitions.
Could anyone help me with an issue I'm facing while building a database wrapper for Prisma in adonis? I am trying to create a typescript definition for it, but I'm unable to import the Database class from providers/DatabaseProvider/database.ts. I've tried recreating the project multiple times, but the issue persists. Thank you smmmm contracts/DatabaseProvider/database.ts
declare module "@ioc:Evermore/Database" {
import Database from "providers/DatabseProvider/database";
const db: Database;
export default db;
}
declare module "@ioc:Evermore/Database" {
import Database from "providers/DatabseProvider/database";
const db: Database;
export default db;
}
providers/DatabaseProvider/index.ts
import type { ApplicationContract } from "@ioc:Adonis/Core/Application";

export default class DatabaseProvider {
constructor(protected app: ApplicationContract) {}

public register() {
// Register your own bindings

this.app.container.singleton("Evermore/Database", () => {
const databaseProv = require("./database").default;
return new databaseProv();
});
}

public async boot() {
// All bindings are ready, feel free to use them
}

public async ready() {
// App is ready
}

public async shutdown() {
// Cleanup, since app is going down
}
}
import type { ApplicationContract } from "@ioc:Adonis/Core/Application";

export default class DatabaseProvider {
constructor(protected app: ApplicationContract) {}

public register() {
// Register your own bindings

this.app.container.singleton("Evermore/Database", () => {
const databaseProv = require("./database").default;
return new databaseProv();
});
}

public async boot() {
// All bindings are ready, feel free to use them
}

public async ready() {
// App is ready
}

public async shutdown() {
// Cleanup, since app is going down
}
}
providers/DatabaseProvider/database.ts
import { PrismaClient } from "@prisma/client";

export default class Database {
protected DB: PrismaClient;
constructor() {
this.DB = new PrismaClient();
}
}
import { PrismaClient } from "@prisma/client";

export default class Database {
protected DB: PrismaClient;
constructor() {
this.DB = new PrismaClient();
}
}
15 replies