The Miniature PowerShell Text Relational Database Management System (tdb) is a lightweight, file-based relational database management system developed using PowerShell. It provides CRUD operations for data storage, retrieval, update, and deletion operations without the need for complex database software.
-
Install the Script: Install the PowerShell script file from PowerShell Gallery.
Install-Script -Name tdb
-
Run the Script:
tdb.ps1
or
tdb
-
Show usage guide
show-tdbUsage
When you run the script for the first time, it will automatically create a configuration file named
.tdb_default.config
with default settings. This file will be located in the same directory where the script is. The default settings include paths for the database directory and the log file. You can modify these settings as needed.Example of default settings in
.tdb_default.config
:{ "DBDirectory": "C:\\Users\\voytas75\\Documents\\tdb\\DB", "LogFilePath": "C:\\Users\\voytas75\\Documents\\tdb\\Logs\\tdb.Log", }
The script uses a configuration file for settings. These settings can be modified in the .tdb_default.config
file.
-
Database Path:
"DBDirectory": ".\\Database"
-
Log File Path:
"LogFilePath": ".\\Database\\log.txt"
Ensure that the paths are correctly set according to your environment.
You can also create your own configuration file and start the program with the -configFilePath
parameter to specify the path to your custom configuration file.
-
Create a Custom Configuration File:
Create a JSON file with your desired settings. For example, create a file named
my_custom_config.json
with the following content:{ "DBDirectory": "D:\\MyCustomDB\\DB", "LogFilePath": "D:\\MyCustomDB\\Logs\\tdb.Log" }
-
Run the Script with Custom Configuration:
Use the
-configFilePath
parameter to specify the path to your custom configuration file when running the script.tdb.ps1 -configFilePath "D:\\MyCustomDB\\my_custom_config.json"
or
tdb -configFilePath "D:\\MyCustomDB\\my_custom_config.json"
This allows you to have multiple configurations and switch between them as needed.
To create a new table, use the New-tdbTable
function. This function requires the table name and the columns you want to include in the table. The table name should only contain alphanumeric characters and underscores.
New-tdbTable -TableName 'Users' -Columns @('Name', 'Email')
To insert a new record into a table, use the Insert-tdbRecord
function. This function requires the table name and a hashtable representing the record.
Insert-tdbRecord -TableName 'Users' -Record @{Name='John Doe'; Email='john@example.com'}
To read records from a table, use the Get-tdbRecord
function. This function requires the table name and a hashtable representing the filter criteria.
get-tdbRecord -TableName "groups1" -ComparisonOperator contains
To update existing records in a table, use the Update-tdbRecords
function. This function requires the table name, a hashtable representing the filter criteria, and a hashtable representing the new values.
Update-tdbRecord -TableName 'Users' -Filter @{ID=1} -NewValues @{Email='john.doe@example.com'}
To delete records from a table, use the Remove-tdbRecords
function. This function requires the table name and a hashtable representing the filter criteria.
Remove-tdbRecord -TableName 'Users' -Filter @{ID=1}
To list all tables in the current database or show info for a specific table, use the Get-tdbTable
function.
Get-tdbTable
If you find the Miniature Powershell Text Relational Database Management System (tdb) useful, consider supporting us on Ko-fi. Your support helps us maintain and improve the project. Thank you!