-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Add README file for SQLite DB example #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| # BrightSign SQLite Database Example | ||
|
|
||
| This example demonstrates how to use SQLite database functionality in a BrightSign application, showing the communication between BrightScript and JavaScript for database operations. | ||
|
|
||
| ## Overview | ||
|
|
||
| The example showcases: | ||
| - Creating a SQLite database | ||
| - Creating tables with SQL commands | ||
| - Inserting records into the database | ||
| - Querying records from the database | ||
| - Deleting records from the database | ||
| - Proper database cleanup and connection management | ||
|
|
||
| ## Files | ||
|
|
||
| - `autorun.brs` - BrightScript application that handles database operations | ||
| - `index.js` - JavaScript application that sends SQL commands via MessagePort | ||
|
|
||
| ## How It Works | ||
|
|
||
| 1. **Initialization**: The BrightScript application (`autorun.brs`) starts and creates a Node.js instance running `index.js` | ||
| 2. **Database Creation**: When the JavaScript app signals it's ready, BrightScript creates a SQLite database at `SD:/example.db` | ||
| 3. **Table Creation**: JavaScript sends a command to create a `users` table with columns for ID, name, and age | ||
| 4. **Data Insertion**: Sample user records are inserted into the database | ||
| 5. **Data Retrieval**: All records are queried from the database | ||
| 6. **Data Deletion**: Each retrieved record is deleted from the database | ||
| 7. **Cleanup**: The database connection is properly closed when the application exits | ||
|
|
||
| ## Database Schema | ||
|
|
||
| The example creates a simple `users` table: | ||
|
|
||
| ```sql | ||
| CREATE TABLE IF NOT EXISTS users ( | ||
| id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
| name TEXT, | ||
| age INTEGER | ||
| ); | ||
| ``` | ||
|
|
||
| ## Sample Data | ||
|
|
||
| The example inserts the following sample records: | ||
| - Alice, age 25 | ||
| - Bob, age 30 | ||
| - Charlie, age 35 | ||
|
|
||
| ## Key Features | ||
|
|
||
| ### BrightScript Side (`autorun.brs`) | ||
| - **Database Management**: Creates and manages SQLite database connection | ||
| - **SQL Statement Execution**: Handles CREATE, INSERT, SELECT, and DELETE operations | ||
| - **Result Processing**: Processes query results and formats them for JavaScript consumption | ||
| - **Error Handling**: Includes error checking for database operations | ||
| - **Resource Cleanup**: Properly closes database connections on exit | ||
|
|
||
| ### JavaScript Side (`index.js`) | ||
| - **MessagePort Communication**: Uses `@brightsign/messageport` for BrightScript communication | ||
| - **Command Orchestration**: Sends SQL commands in logical sequence | ||
| - **Data Processing**: Parses and processes database results | ||
| - **Event-Driven Architecture**: Responds to database operation completion events | ||
|
|
||
| ## Running the Example | ||
|
|
||
| 1. Copy the `autorun.brs` and `index.js` files to the root of your BrightSign player's SD card | ||
| 2. Power on or restart your BrightSign player | ||
| 3. The application will automatically start and demonstrate the database operations | ||
| 4. Check the device logs to see the SQL operations being performed | ||
|
|
||
| ## Expected Output | ||
|
|
||
| The application will log information about each database operation: | ||
| - Database creation confirmation | ||
| - Table creation success | ||
| - Record insertion confirmations | ||
| - Retrieved records display | ||
| - Record deletion confirmations | ||
|
|
||
| ## Notes | ||
|
|
||
| - The database file is created at `SD:/example.db` | ||
| - The application demonstrates a complete CRUD (Create, Read, Update, Delete) cycle | ||
| - Error handling is included for robust database operations | ||
| - The database connection is automatically closed when the Nodejs application exits | ||
blshukla marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - Results from SELECT queries are formatted as JSON strings for JavaScript processing | ||
|
|
||
| This example serves as a foundation for building more complex database-driven BrightSign applications. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.