Skip to content

Custom in-memory database and SQL-like Query Language implemented in Scala. It supports core table operations like insert, select, filter (with complex conditions), sort, and joins. Designed as a homework assignment to demonstrate database internals and functional programming concepts for managing data interactions.

Notifications You must be signed in to change notification settings

GeorgeGrasu/Custom-In-Memory-Database

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Custom In-Memory Database

This project is a homework assignment focused on implementing a Query Language inspired by SQL, built upon a custom in-memory database.

The goal is to implement operations on individual tables as well as interactions between multiple tables, allowing for complex data manipulation and querying.

Features

This project implements a lightweight database engine with the following capabilities:

Table Operations

  • Insert: Add new rows to a table.
  • Delete: Remove rows from a table.
  • Sort: detailed sorting of table data by column.
  • Select: Project specific columns from a table.
  • Filter: Apply complex conditions to filter rows.
  • Join: Perform inner/outer joins between two tables.
  • Cartesian Product: Generate the Cartesian product of two tables.

Database Operations

  • Manage Tables: Create, retrieve, and delete tables within a database instance.

Query Language

The project includes a domain-specific language (DSL) for filtering data:

  • Filter Conditions: Equal, And, Or, Not.
  • Complex Queries: Pre-defined queries for common use cases (e.g., finding customers by age and city, filtering orders by date).

Project Structure

  • src/main/scala/Table.scala: Core data structure representing a database table.
  • src/main/scala/Database.scala: Manages a collection of tables.
  • src/main/scala/FilterCond.scala: Defines the filtering logic and conditions.
  • src/main/scala/Queries.scala: Contains specific business logic queries.
  • src/test/scala/: Contains unit tests for the application.

Prerequisites

  • Scala: Version 3.3.1 or higher.
  • sbt: The Scala Build Tool. Install sbt.

Note: This environment does not have sbt pre-installed. You will need to install it to build and run the project.

Installation & Usage

  1. Clone the repository:

    git clone <repository_url>
    cd tema2
  2. Run Tests: Execute the unit tests to verify the implementation.

    sbt test
  3. Run the Application: You can use the sbt console to interact with the code:

    sbt console

    Then, inside the REPL:

    import Table._
    import Database._
    
    val db = Database(List())
    val newDb = db.insert("Users")
    println(newDb)

Examples

Creating a Table from CSV

val csvData = """
name,age,city
Alice,30,New York
Bob,25,Los Angeles
"""
val table = Table.fromCSV(csvData)

Filtering Data

import FilterCond._

// Assuming 'table' exists
val filter = Field("age", _.toInt > 20)
val filteredTable = table.filter(filter)

About

Custom in-memory database and SQL-like Query Language implemented in Scala. It supports core table operations like insert, select, filter (with complex conditions), sort, and joins. Designed as a homework assignment to demonstrate database internals and functional programming concepts for managing data interactions.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages