Connecting to a database in Python
Import the database class.
import AlphaDB from "@w-kuipers/alphadb";Initialize an instance and connect it to a database using MySQL credentials.
const db = new AlphaDB();
db.connect({
host: "localhost",
user: "user",
password: "password",
database: "database",
})It might be a good idea to run this in an async function so that the connection can be awaited before any other methods are called.
const connect = async() => {
const db = new AlphaDB();
await db.connect({
host: "localhost",
user: "user",
password: "password",
database: "database",
})
}Replace the credentials with your own. AlphaDB requires the user to have the following privileges: CREATE, INSERT, DELETE, SELECT, UPDATE, ALTER, DROP and REFERENCES.