oscarthroedsson
oscarthroedsson
Explore posts from servers
PPrisma
Created by oscarthroedsson on 3/14/2024 in #help-and-questions
Multiple datasources
Wondering if I can use something like this:
const mongoDB = new PrismaClient({
datasourceUrl: 'MONGO uri',
})
const mongoDB = new PrismaClient({
datasourceUrl: 'MONGO uri',
})
I am also wondering how the connection with DB and collection goes with prisma. I am doing old fashion right now. But they use prisma for mySQL and i thought it would be better to use prisma for both, it we can.
import mongoose from "mongoose"; //connects to DB
import { MongoClient } from "mongodb";
//process.env.API_KEY

const uri = process.env.MONGO_URL;
const databaseName = process.env.MONGO_DB_NAME;
const collectionName = process.env.MONGO_COLLECTION;

console.log("🔗 URI: ", uri);
console.log("DB NAME: ", databaseName);
console.log("DB NAME: ", collectionName);

const client = new MongoClient(uri);
const database = client.db(databaseName);

const connectToDatabase = async () => {
try {
await mongoose.connect(uri);
console.log("🍃 | Successfully connected to MongoDB. 🎉");
} catch (error) {
console.error("🧹 | Could not connect to MongoDB: ", error);
}
};
connectToDatabase();

export function mongoDBstring() {
const wholeColl = client.db(databaseName).collection(collectionName);
return wholeColl;
}
import mongoose from "mongoose"; //connects to DB
import { MongoClient } from "mongodb";
//process.env.API_KEY

const uri = process.env.MONGO_URL;
const databaseName = process.env.MONGO_DB_NAME;
const collectionName = process.env.MONGO_COLLECTION;

console.log("🔗 URI: ", uri);
console.log("DB NAME: ", databaseName);
console.log("DB NAME: ", collectionName);

const client = new MongoClient(uri);
const database = client.db(databaseName);

const connectToDatabase = async () => {
try {
await mongoose.connect(uri);
console.log("🍃 | Successfully connected to MongoDB. 🎉");
} catch (error) {
console.error("🧹 | Could not connect to MongoDB: ", error);
}
};
connectToDatabase();

export function mongoDBstring() {
const wholeColl = client.db(databaseName).collection(collectionName);
return wholeColl;
}
3 replies
KPCKevin Powell - Community
Created by oscarthroedsson on 9/13/2023 in #front-end
Position:relative is confusing me
The code if someone wants to see it: Code: React components.
return (
<>
<Nav></Nav>
<header className="xs:w-full xs:h-auto xs:m-0 xs:rounded-lg xs: xs:rounded-lg xs:p-10 headerBg ">
<div className="xs:text-center">
<p className="text-center py-4">
<span className="text-main-color heavy-p font-semi-p">
Brottskollen.se
</span>{" "}
ger dig
</p>
<h1 className="xs:text-4xl text-center font-semi-p">
Statistik på Sveriges Kriminalitet
</h1>
<p className="text-center py-6">helt ocencuerat</p>
</div>
<div className="text-center">
<p className=" text-5xl font-semi-p">1 478 291</p>
<p>reg polishändelser i år</p>
</div>
<div className=" flex-wrap flex-auto xsRelative flex items-center"> //here is position:relative applyed
<ListBox></ListBox>
<CommonCrime></CommonCrime>
<WeekData></WeekData>
</div>
</header>
<main className="mt-20">
<section>
<header>
<h2>Should not be here</h2>
<p></p>
</header>
</section>
</main>
<ul>
{latestCrimes.map((info) => {
return <li key={info.id}>{info.type}</li>;
})}
</ul>
</>
);
}
return (
<>
<Nav></Nav>
<header className="xs:w-full xs:h-auto xs:m-0 xs:rounded-lg xs: xs:rounded-lg xs:p-10 headerBg ">
<div className="xs:text-center">
<p className="text-center py-4">
<span className="text-main-color heavy-p font-semi-p">
Brottskollen.se
</span>{" "}
ger dig
</p>
<h1 className="xs:text-4xl text-center font-semi-p">
Statistik på Sveriges Kriminalitet
</h1>
<p className="text-center py-6">helt ocencuerat</p>
</div>
<div className="text-center">
<p className=" text-5xl font-semi-p">1 478 291</p>
<p>reg polishändelser i år</p>
</div>
<div className=" flex-wrap flex-auto xsRelative flex items-center"> //here is position:relative applyed
<ListBox></ListBox>
<CommonCrime></CommonCrime>
<WeekData></WeekData>
</div>
</header>
<main className="mt-20">
<section>
<header>
<h2>Should not be here</h2>
<p></p>
</header>
</section>
</main>
<ul>
{latestCrimes.map((info) => {
return <li key={info.id}>{info.type}</li>;
})}
</ul>
</>
);
}
//The class:
.xsRelative {
position: relative;
top: 140px;
gap: 50px;
display: flex;
align-items: center;
justify-content: center;
}
.xsRelative {
position: relative;
top: 140px;
gap: 50px;
display: flex;
align-items: center;
justify-content: center;
}
3 replies