-
Notifications
You must be signed in to change notification settings - Fork 3
Core 2637/data loader #4
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
Draft
heskew
wants to merge
3
commits into
main
Choose a base branch
from
CORE-2637/data-loader
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 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
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,73 @@ | ||
| # HarperDB Data Loader | ||
|
|
||
| This directory contains YAML or JSON files that are automatically loaded into your HarperDB database tables when your application starts. | ||
|
|
||
| ## How It Works | ||
|
|
||
| 1. Place data files in this directory with `.yaml`, `.yml`, or `.json` extensions | ||
| 2. Files are processed when HarperDB starts | ||
| 3. Records are inserted/updated based on file modification time: | ||
| - New records are always added | ||
| - Existing records are only updated if the file's modification time is newer than the record's stored timestamp | ||
| - Records with timestamps newer than the file's modification time are preserved unchanged | ||
|
|
||
| ## File Format | ||
|
|
||
| Data files must contain `table` and `records` fields. The `database` field is optional. | ||
|
|
||
| ### JSON Example | ||
|
|
||
| ```json | ||
| { | ||
| "database": "dev", // Optional - uses default database if omitted | ||
| "table": "Product", // Required - name of the table | ||
| "records": [ // Required - array of records | ||
| { | ||
| "id": "1", // Primary key field | ||
| "name": "Laptop", | ||
| "price": 999.99 | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| ### YAML Example | ||
|
|
||
| ```yaml | ||
| database: dev # Optional - uses default database if omitted | ||
| table: products # Required - name of the table | ||
| records: # Required - array of records | ||
| - id: 1 # Primary key field | ||
| name: "Laptop" | ||
| price: 999.99 | ||
| ``` | ||
|
|
||
| ## Key Features | ||
|
|
||
| - **Automatic Table Creation**: Tables are created if they don't exist | ||
| - **Primary Key Detection**: The `id` field is automatically detected as the primary key | ||
| - **File Modification Time**: | ||
| - The data loader uses the file's modification time (`mtime`) to determine if records should be updated | ||
| - "Touching" a file (updating its modification time) will force a reload of its data | ||
| - This allows for simpler data files without timestamp properties in the records | ||
| - **Multi-file Support**: You can have multiple data files for different tables | ||
| - **Complex Data Types**: Supports nested objects, arrays, and various data types | ||
| - **One Table Per File**: Each file should define one table | ||
|
|
||
| ## Tips for Managing Data | ||
|
|
||
| - To force a reload of data, simply update the file's modification time: | ||
| ```bash | ||
| # Update the file's timestamp using touch | ||
| touch data/products.json | ||
| ``` | ||
| - If you need to restore to previous data, you can replace the file and update its timestamp | ||
| - The system automatically handles the comparison between file modification time and record timestamps | ||
|
|
||
| ## Sample Files | ||
|
|
||
| - `categories.json`: Category data with parent/child relationships | ||
| - `products.json`: Product data with references to categories | ||
| - `users.json`: User account data | ||
|
|
||
| These sample files demonstrate common data patterns and relationships. | ||
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,26 @@ | ||
| { | ||
| "table": "Category", | ||
| "records": [ | ||
| { | ||
| "id": "electronics", | ||
| "name": "Electronics", | ||
| "description": "Electronic devices and gadgets. LFG!!1" | ||
| }, | ||
| { | ||
| "id": "furniture", | ||
| "name": "Furniture", | ||
| "description": "Home and office furniture" | ||
| }, | ||
| { | ||
| "id": "clothing", | ||
| "name": "Clothing", | ||
| "description": "Apparel and accessories" | ||
| }, | ||
| { | ||
| "id": "pants", | ||
| "name": "Pants", | ||
| "description": "Apparel and accessories", | ||
| "categoryId": "clothing" | ||
| } | ||
| ] | ||
| } |
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,37 @@ | ||
| { | ||
| "table": "Product", | ||
| "records": [ | ||
| { | ||
| "id": "1", | ||
| "name": "Laptop", | ||
| "price": 999.99, | ||
| "categoryId": "electronics", | ||
| "inStock": true | ||
| }, | ||
| { | ||
| "id": "2", | ||
| "name": "Smartphone", | ||
| "price": 699.99, | ||
| "categoryId": "electronics", | ||
| "inStock": false | ||
| }, | ||
| { | ||
| "id": "3", | ||
| "name": "Desk Chair", | ||
| "price": 199.99, | ||
| "categoryId": "furniture", | ||
| "details": { | ||
| "weight": 1.5, | ||
| "color": "black" | ||
| }, | ||
| "inStock": true | ||
| }, | ||
| { | ||
| "id": "4", | ||
| "name": "Jeans", | ||
| "price": 98.99, | ||
| "categoryId": "pants", | ||
| "inStock": true | ||
| } | ||
| ] | ||
| } |
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,63 @@ | ||
| # This is a sample YAML data file for HarperDB Data Loader | ||
| # Format: { database, table, records[] } | ||
| # | ||
| # This example shows inserting tables and records into a | ||
| # specific database, instead of the default 'data' database. | ||
| # | ||
| # Example: Products for an e-commerce application | ||
| # ```yaml | ||
| # database: dev | ||
| # table: products | ||
| # records: | ||
| # - id: 1 | ||
| # name: "Laptop" | ||
| # price: 999.99 | ||
| # category: "Electronics" | ||
| # inStock: true | ||
| # __createdtime__: 1682752800000 | ||
| # __updatedtime__: 1682752800000 | ||
| # - id: 2 | ||
| # name: "Smartphone" | ||
| # price: 699.99 | ||
| # category: "Electronics" | ||
| # inStock: false | ||
| # __createdtime__: 1682752801000 | ||
| # __updatedtime__: 1682752801000 | ||
| # - id: 3 | ||
| # name: "Desk Chair" | ||
| # price: 199.99 | ||
| # category: "Furniture" | ||
| # inStock: true | ||
| # __createdtime__: 1682752802000 | ||
| # __updatedtime__: 1682752802000 | ||
| # ``` | ||
| # | ||
| # If you need to load data into multiple tables, use separate files | ||
| # for each table. For example: | ||
| # | ||
| # categories.yaml: | ||
| # ```yaml | ||
| # database: dev | ||
| # table: categories | ||
| # records: | ||
| # - id: "electronics" | ||
| # name: "Electronics" | ||
| # description: "Electronic devices and gadgets" | ||
| # __createdtime__: 1682752803000 | ||
| # __updatedtime__: 1682752803000 | ||
| # ``` | ||
| # | ||
| # users.yaml: | ||
| # ```yaml | ||
| # database: dev | ||
| # table: users | ||
| # records: | ||
| # - id: 1 | ||
| # username: "john_doe" | ||
| # email: "john@example.com" | ||
| # firstName: "John" | ||
| # lastName: "Doe" | ||
| # active: true | ||
| # __createdtime__: 1682752806000 | ||
| # __updatedtime__: 1682752806000 | ||
| # ``` |
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,20 @@ | ||
| { | ||
| "database": "myco", | ||
| "table": "User", | ||
| "records": [ | ||
| { | ||
| "id": "1", | ||
| "username": "jane_doe", | ||
| "email": "jane@example.com", | ||
| "firstName": "Jane", | ||
| "lastName": "Doe" | ||
| }, | ||
| { | ||
| "id": "2", | ||
| "username": "Jon_smith", | ||
| "email": "jon@example.com", | ||
| "firstName": "Jon", | ||
| "lastName": "Smith" | ||
| } | ||
| ] | ||
| } |
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,19 @@ | ||
| { | ||
| "table": "User", | ||
| "records": [ | ||
| { | ||
| "id": "1", | ||
| "username": "john_doe", | ||
| "email": "john@example.com", | ||
| "firstName": "John", | ||
| "lastName": "Doe" | ||
| }, | ||
| { | ||
| "id": "2", | ||
| "username": "jane_smith", | ||
| "email": "jane@example.com", | ||
| "firstName": "Jane", | ||
| "lastName": "Smith" | ||
| } | ||
| ] | ||
| } |
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 |
|---|---|---|
| @@ -1,7 +1,45 @@ | ||
| ## Here we can define any tables in our database. This example shows how we define a type as a table using | ||
| ## the type name as the table name and specifying it is an "export" available in the REST and other external protocols. | ||
| ## This schema defines the data model for our application. | ||
| ## Each type with the @table directive becomes a table in the database. | ||
| ## The @export directive makes it available in the REST API and other external protocols. | ||
|
|
||
| ## Example table for reference | ||
| type TableName @table @export { | ||
| id: ID @primaryKey # Here we define primary key (must be one) | ||
| name: String # we can define any other attributes here | ||
| tag: String @indexed # we can specify any attributes that should be indexed | ||
| } | ||
|
|
||
| ## Example tables for data loader example | ||
| type Product @table @export { | ||
| id: ID @primaryKey | ||
| name: String @indexed | ||
| price: Float | ||
| category: Category @relationship(from: "categoryId") | ||
| details: Any | ||
| inStock: Boolean | ||
| } | ||
|
|
||
| type Category @table @export { | ||
| id: ID @primaryKey | ||
| name: String @indexed | ||
| description: String | ||
| parent: Category @relationship(from: "categoryId") | ||
| products: [Product] @relationship(to: "categoryId") | ||
| children: [Category] @relationship(to: "categoryId") | ||
| } | ||
|
|
||
| type User @table @export { | ||
| id: ID @primaryKey | ||
| username: String @indexed | ||
| email: String @indexed | ||
| firstName: String | ||
| lastName: String | ||
| } | ||
|
|
||
| type MycoUser @table(database: "myco", table: "User") @export { | ||
| id: ID @primaryKey | ||
| username: String @indexed | ||
| email: String @indexed | ||
| firstName: String | ||
| lastName: String | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this based off of the corresponding schema? What if I don't specify a schema?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The data loader tries to infer some simple schema based on the data (i.e. attribute names and types)... The more real use cases we can test the better. Should also have some better real example in here.