I have specific .sql file to create new database and table, insert data.

I can parse the database and tables with MariaDB server and simple node.js application.

(Just read .sql file and run each SQL query in MariaDB server using mariadb NPM, and convert to JSON format)

// Example simple code I used
import mariadb from "mariadb"; // It use mariaDB server - I don't want to use DB server

const pool = mariadb.createPool({ host, user, password, connectionLimit: 10 });
const queries = readSQLFile('./sample_sql_file.sql'); // The SQL file include thousands SQL queries
const connection = pool.getConnection();

const dataJson = {}; // Result of database, JSON format

for(const query of queries) {
    await connection.query(query); // Execute each SQL line and save result in MariaDB database
}

const tables = (await connection.query(`show tables in ${PROJECT_DATABASE}`)).map(
    (e) => e[`Tables_in_${PROJECT_DATABASE}`]
);

for (const table of tables) {
    const data = await conn.query(`SELECT * FROM `${table}``);
    dataJson[table] = [...data];
}

But actually I want is that without MariaDB server.

How can I parse all SQL queries in .sql file and get all data without any database server?

// Example concept code I want
import VirtualDatabase from "somethimg"; // Actually I need it, it doesn't use any database server

const queries = readSQLFile('./sample_sql_file.sql'); // The SQL file include thousands SQL queries
const dataJson = {}; // Result of database, JSON format

const database = new VirtualDatabase();

for(const query of queries) {
    database.runQuery(query); // Run each query line, and generate database and tables
}

const tables = database.getTables(); // Gets all tables in database;

for (const table of tables) {
    const data = database.getData(table);
    dataJson[table] = [...data];
}

As-Is

  1. Prepare .sql file
  2. Create database into MariaDB using .sql file
  3. Read database in MariaDB server using mariadb NPM module
  4. Generate JSON format using the read database

To-Be

  1. Prepare .sql file
  2. Just read .sql file in Node.js
  3. Parse the whole queries in .sql file
  4. Generate JSON format using the read database