-
Notifications
You must be signed in to change notification settings - Fork 0
feat: support to build SQLite database #22
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
Conversation
…alogs, updating references in documentation and code accordingly
…and package-lock.json
… and add SqlDelight documentation
… and shooting rules with corresponding queries
…l (default all); output to db/realm and db/sqlite with extracted DDL
… schema duplication
…N during DB build
…sh for improved database generation and verification
…tabase schema version
…ions for G17 CUSTOM, G17 Gen.5 MOS, P320, and G19 Gen.5 MOS
…d field specifications
…nd modify existing entries for clarity
…r real firearm counterparts in the database
…criptions and unify format for consistency
… refine shooting challenge descriptions in CSV
|
/gemini summary |
Summary of ChangesThis pull request significantly enhances the project's data generation capabilities by introducing support for SQLite databases in addition to the existing Realm format. This change provides greater versatility for applications consuming the catalog data. It involves a refactoring of the database build process, including a new unified build script, updated documentation, and the integration of Highlights
Changelog
Activity
|
Summary of ChangesThis pull request significantly expands the project's data management capabilities by introducing comprehensive support for building SQLite databases, complementing the existing Realm database generation. The changes involve a refactored and unified build process, updated documentation to reflect the new database formats and source file naming conventions, and the integration of Highlights
Changelog
Activity
|
|
/gemini review |
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.
Code Review
This pull request introduces support for building SQLite databases alongside the existing Realm database generation. The changes are comprehensive, including a new build script, updated documentation, new dependencies for SQLite, and the core logic for data migration from CSVs to an SQLite database. The implementation is well-structured, sharing parsing logic between both database types. My review includes a few suggestions to improve the robustness of the build scripts and enhance type safety and maintainability in the new TypeScript code.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…eturn types for parsed CSV data
…troducing a helper function to check for statement terminators
|
/gemini review |
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.
Code Review
This pull request introduces support for building a SQLite database alongside the existing Realm database. The changes include adding a new build script, command-line options for format selection, SQLite schema definitions (.sq files), and the implementation for parsing CSVs and populating the SQLite database. The documentation has also been updated to reflect these changes.
My review focuses on improving script robustness, code clarity, and schema consistency. I've suggested using path.join for constructing file paths, simplifying the build script, and aligning column naming conventions in the new SQLite schema for better maintainability.
| CREATE TABLE manufacturers( | ||
| id TEXT NOT NULL PRIMARY KEY, | ||
| shortName TEXT, | ||
| longName TEXT, | ||
| altName TEXT, | ||
| description TEXT, | ||
| url TEXT, | ||
| shortNameJa TEXT, | ||
| longNameJa TEXT, | ||
| altNameJa TEXT, | ||
| descriptionJa TEXT, | ||
| urlJa TEXT | ||
| ); |
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.
For schema consistency, consider renaming the primary key column id to _id. Other tables in the schema (guns, shooting_rules, catalog_metadata) use _id as the primary key. This change would make the schema more uniform and easier to understand. You will also need to update the corresponding INSERT statement in src/sqldelight/index.ts.
CREATE TABLE manufacturers(
_id TEXT NOT NULL PRIMARY KEY,
shortName TEXT,
longName TEXT,
altName TEXT,
description TEXT,
url TEXT,
shortNameJa TEXT,
longNameJa TEXT,
altNameJa TEXT,
descriptionJa TEXT,
urlJa TEXT
);
| SELECT * FROM manufacturers; | ||
|
|
||
| selectById: | ||
| SELECT * FROM manufacturers WHERE id = ?1; |
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.
| file = `${directory}ManufacturerCatalog.csv`; | ||
| console.log(`\nWriting manufacturer catalog from ${file}`) | ||
| success = createManufacturerCatalog(realm, `${file}`); | ||
| console.log(`${success ? "Done" : "FAILED"}`); | ||
|
|
||
| file = `${directory}RealmGunCatalog.csv`; | ||
| file = `${directory}GunCatalog.csv`; | ||
| console.log(`\nWriting gun catalog from ${file}`) | ||
| success = createGunCatalog(realm, `${file}`); | ||
| console.log(`${success ? "Done" : "FAILED"}`); | ||
|
|
||
| file = `${directory}RealmShootingRuleCatalog.csv`; | ||
| file = `${directory}ShootingRuleCatalog.csv`; | ||
| console.log(`\nWriting shooting rule catalog from ${file}`) | ||
| success = createShootingRuleCatalog(realm, `${file}`); | ||
| console.log(`${success ? "Done" : "FAILED"}`); |
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.
Using path.join() to construct file paths is more robust than string concatenation. It correctly handles path separators across different operating systems and avoids potential issues like double slashes.
| file = `${directory}ManufacturerCatalog.csv`; | |
| console.log(`\nWriting manufacturer catalog from ${file}`) | |
| success = createManufacturerCatalog(realm, `${file}`); | |
| console.log(`${success ? "Done" : "FAILED"}`); | |
| file = `${directory}RealmGunCatalog.csv`; | |
| file = `${directory}GunCatalog.csv`; | |
| console.log(`\nWriting gun catalog from ${file}`) | |
| success = createGunCatalog(realm, `${file}`); | |
| console.log(`${success ? "Done" : "FAILED"}`); | |
| file = `${directory}RealmShootingRuleCatalog.csv`; | |
| file = `${directory}ShootingRuleCatalog.csv`; | |
| console.log(`\nWriting shooting rule catalog from ${file}`) | |
| success = createShootingRuleCatalog(realm, `${file}`); | |
| console.log(`${success ? "Done" : "FAILED"}`); | |
| file = path.join(directory, 'ManufacturerCatalog.csv'); | |
| console.log(`\nWriting manufacturer catalog from ${file}`) | |
| success = createManufacturerCatalog(realm, file); | |
| console.log(`${success ? "Done" : "FAILED"}`); | |
| file = path.join(directory, 'GunCatalog.csv'); | |
| console.log(`\nWriting gun catalog from ${file}`) | |
| success = createGunCatalog(realm, file); | |
| console.log(`${success ? "Done" : "FAILED"}`); | |
| file = path.join(directory, 'ShootingRuleCatalog.csv'); | |
| console.log(`\nWriting shooting rule catalog from ${file}`) | |
| success = createShootingRuleCatalog(realm, file); | |
| console.log(`${success ? "Done" : "FAILED"}`); |
| `INSERT INTO manufacturers (id, shortName, longName, altName, description, url, shortNameJa, longNameJa, altNameJa, descriptionJa, urlJa) | ||
| VALUES (@_id, @shortName, @longName, @altName, @description, @url, @shortNameJa, @longNameJa, @altNameJa, @descriptionJa, @urlJa)` | ||
| ); |
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.
This INSERT statement needs to be updated if you rename the id column to _id in the manufacturers table for consistency, as suggested in sqldelight/catalog/Manufacturer.sq.
| `INSERT INTO manufacturers (id, shortName, longName, altName, description, url, shortNameJa, longNameJa, altNameJa, descriptionJa, urlJa) | |
| VALUES (@_id, @shortName, @longName, @altName, @description, @url, @shortNameJa, @longNameJa, @altNameJa, @descriptionJa, @urlJa)` | |
| ); | |
| `INSERT INTO manufacturers (_id, shortName, longName, altName, description, url, shortNameJa, longNameJa, altNameJa, descriptionJa, urlJa) | |
| VALUES (@_id, @shortName, @longName, @altName, @description, @url, @shortNameJa, @longNameJa, @altNameJa, @descriptionJa, @urlJa)` |
| const manufacturers = ParseCSV.parseCsvFile( | ||
| path.normalize(`${directory}ManufacturerCatalog.csv`), | ||
| RealmManufacturerCatalog.schema as any | ||
| ) as (IManufacturerCatalog | null)[]; | ||
|
|
||
| const guns = ParseCSV.parseCsvFile( | ||
| path.normalize(`${directory}GunCatalog.csv`), | ||
| RealmGunCatalog.schema as any | ||
| ) as (IGunCatalog | null)[]; | ||
|
|
||
| const shootingRules = ParseCSV.parseCsvFile( | ||
| path.normalize(`${directory}ShootingRuleCatalog.csv`), | ||
| RealmShootingRuleCatalog.schema as any | ||
| ) as (IShootingRuleCatalog | null)[]; |
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.
For robustness and cross-platform compatibility, it's better to use path.join() to construct file paths instead of string concatenation with path.normalize().
| const manufacturers = ParseCSV.parseCsvFile( | |
| path.normalize(`${directory}ManufacturerCatalog.csv`), | |
| RealmManufacturerCatalog.schema as any | |
| ) as (IManufacturerCatalog | null)[]; | |
| const guns = ParseCSV.parseCsvFile( | |
| path.normalize(`${directory}GunCatalog.csv`), | |
| RealmGunCatalog.schema as any | |
| ) as (IGunCatalog | null)[]; | |
| const shootingRules = ParseCSV.parseCsvFile( | |
| path.normalize(`${directory}ShootingRuleCatalog.csv`), | |
| RealmShootingRuleCatalog.schema as any | |
| ) as (IShootingRuleCatalog | null)[]; | |
| const manufacturers = ParseCSV.parseCsvFile( | |
| path.join(directory, "ManufacturerCatalog.csv"), | |
| RealmManufacturerCatalog.schema as any | |
| ) as (IManufacturerCatalog | null)[]; | |
| const guns = ParseCSV.parseCsvFile( | |
| path.join(directory, "GunCatalog.csv"), | |
| RealmGunCatalog.schema as any | |
| ) as (IGunCatalog | null)[]; | |
| const shootingRules = ParseCSV.parseCsvFile( | |
| path.join(directory, "ShootingRuleCatalog.csv"), | |
| RealmShootingRuleCatalog.schema as any | |
| ) as (IShootingRuleCatalog | null)[]; |
No description provided.