Change Database

This commit is contained in:
Randa Firman Putra
2025-06-20 00:45:19 +07:00
parent e028039ee2
commit 2f7ab6c0a9
45 changed files with 1896 additions and 953 deletions

View File

@@ -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 };