Change Database
This commit is contained in:
33
lib/db.ts
33
lib/db.ts
@@ -1,22 +1,25 @@
|
||||
import mysql from 'mysql2/promise';
|
||||
import { createClient } from '@supabase/supabase-js';
|
||||
|
||||
const pool = mysql.createPool({
|
||||
host: '127.0.0.1',
|
||||
port: 3306,
|
||||
user: 'root',
|
||||
password: 'semogabisayok321',
|
||||
database: 'mhsdb',
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0
|
||||
});
|
||||
// Initialize Supabase client
|
||||
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL!;
|
||||
const supabaseKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!;
|
||||
|
||||
const supabase = createClient(supabaseUrl, supabaseKey);
|
||||
|
||||
// Test the connection
|
||||
const testConnection = async () => {
|
||||
try {
|
||||
const connection = await pool.getConnection();
|
||||
const { data, error } = await supabase
|
||||
.from('mahasiswa')
|
||||
.select('count')
|
||||
.limit(1);
|
||||
|
||||
if (error) {
|
||||
console.error('Database connection failed:', error);
|
||||
return false;
|
||||
}
|
||||
|
||||
console.log('Database connection successful');
|
||||
connection.release();
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Database connection failed:', error);
|
||||
@@ -24,5 +27,5 @@ const testConnection = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
// Export both the pool and the test function
|
||||
export { pool as default, testConnection };
|
||||
// Export both the client and the test function
|
||||
export { supabase as default, testConnection };
|
||||
Reference in New Issue
Block a user