Skip to content

Conversation

@tinoue
Copy link
Collaborator

@tinoue tinoue commented Oct 21, 2025

No description provided.

tinoue added 20 commits August 12, 2025 10:12
…alogs, updating references in documentation and code accordingly
… and shooting rules with corresponding queries
…l (default all); output to db/realm and db/sqlite with extracted DDL
…sh for improved database generation and verification
…ions for G17 CUSTOM, G17 Gen.5 MOS, P320, and G19 Gen.5 MOS
… refine shooting challenge descriptions in CSV
@precisionmarks
Copy link
Contributor

/gemini summary

@gemini-code-assist
Copy link
Contributor

Summary of Changes

This 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 better-sqlite3 for SQLite creation. The underlying data schemas and some catalog entries have also been refined to support these new functionalities.

Highlights

  • SQLite Database Support: Introduced the capability to build SQLite databases alongside the existing Realm databases, providing more flexibility for data consumption.
  • Unified Database Build Script: Replaced the old create_database.sh with a new build-databases.sh script that can generate both Realm and SQLite databases, with options to specify the desired output format.
  • CSV File Renaming and Documentation Updates: Renamed core CSV source files (e.g., RealmGunCatalog.csv to GunCatalog.csv) and updated README.md and related documentation to reflect these changes and the new build process.
  • New SqlDelight Integration: Added a new sqldelight directory containing SQL schema definitions and TypeScript logic for creating and populating SQLite databases using better-sqlite3.
  • Enhanced Git Check in Build Process: The scripts/create-database.sh script now includes an option to skip git checks and intelligently excludes generated database files from untracked file warnings.
  • Schema Version Update and Data Enhancements: The internal SCHEMA_VERSION has been updated from 2 to 4, and several shooting rules in ShootingRuleCatalog.csv have been refined, including new WFDA rules and updated descriptions.
Changelog
  • .gitignore
    • Added temp_db/* to ignore temporary database files.
  • README.md
    • Updated the database creation command from create_database.sh to build-databases.sh.
    • Added a new section detailing output formats (realm, sqlite, all) and options for database generation.
    • Specified output paths for both Realm and SQLite databases and their commit ID files.
    • Updated references to CSV source files, removing 'Realm' prefix (e.g., RealmGunCatalog.csv to GunCatalog.csv).
    • Added examples for generating specific database formats.
  • build-databases.sh
    • Added new script to manage the creation of both Realm and SQLite databases.
    • Includes directory setup, calls to npm run create-database, and verification of generated database files.
  • create_database.sh
    • Removed, as its functionality is superseded by build-databases.sh.
  • db/realm/catalog_data.realm.commitid
    • Added a new commit ID file for the Realm database.
  • db/sqlite/catalog_data.db.commitid
    • Added a new commit ID file for the SQLite database.
  • db/sqlite/catalog_schema.sql
    • Added a new file containing auto-generated SQL DDL statements for catalog_metadata, guns, manufacturers, and shooting_rules tables, extracted from SqlDelight .sq files.
  • docs/GunCatalog.md
    • Updated the referenced CSV file name from source_data/RealmGunCatalog.csv to source_data/GunCatalog.csv.
    • Updated the manufacturerId field description to reference ManufacturerCatalog.csv.
  • docs/ManufacturerCatalog.md
    • Updated the referenced CSV file name from source_data/RealmManufacturerCatalog.csv to source_data/ManufacturerCatalog.csv.
  • docs/RealName.md
    • Added new documentation (in Japanese) discussing the addition of real firearm names to gun descriptions for improved searchability.
  • docs/ShootingRuleCatalog.md
    • Added new documentation for the ShootingRuleCatalog.csv schema, detailing fields, enum values for positions, gun types, sight types, and units of range.
  • docs/SqlDelightSupport.md
    • Added new documentation (in Japanese) outlining the plan and implementation hints for SqlDelight (SQLite3) data creation.
  • package-lock.json
    • Added better-sqlite3 and @types/better-sqlite3 as new dependencies.
  • package.json
    • Added better-sqlite3 and @types/better-sqlite3 to the project dependencies.
  • realm_data/catalog_data.realm.commitid
    • Removed old commit ID file, replaced by db/realm/catalog_data.realm.commitid.
  • scripts/create-database.sh
    • Introduced a --no-git-check option to bypass untracked file checks.
    • Modified the untracked files check to exclude files within the db/ directory.
  • source_data/GunCatalog.csv
    • Renamed from source_data/RealmGunCatalog.csv.
    • Updated description and descriptionJa fields for several gun entries (e.g., 'G17 CUSTOM', 'P320', 'G19 Gen.5 MOS') to include real firearm names.
  • source_data/ManufacturerCatalog.csv
    • Renamed from source_data/RealmManufacturerCatalog.csv.
  • source_data/ShootingRuleCatalog.csv
    • Renamed from source_data/RealmShootingRuleCatalog.csv.
    • Updated descriptions and range100x values for existing shooting rules.
    • Added new WFDA (World Fast Draw Association) rules for fast draw competitions.
  • sqldelight/catalog/CatalogMetadata.sq
    • Added new SQL schema definition for the catalog_metadata table.
  • sqldelight/catalog/Gun.sq
    • Added new SQL schema definition for the guns table, including an index on manufacturerId and a comprehensive search query.
  • sqldelight/catalog/Manufacturer.sq
    • Added new SQL schema definition for the manufacturers table, including a searchByKeyword query.
  • sqldelight/catalog/ShootingRule.sq
    • Added new SQL schema definition for the shooting_rules table.
  • src/createGunCatalog.ts
    • Updated the default file path for the gun catalog CSV to source_data/GunCatalog.csv.
  • src/createManufacturerCatalog.ts
    • Updated the default file path for the manufacturer catalog CSV to source_data/ManufacturerCatalog.csv.
  • src/createShootingRuleCatalog.ts
    • Updated the default file path for the shooting rule catalog CSV to source_data/ShootingRuleCatalog.csv.
  • src/index.ts
    • Imported buildSqlite function for SQLite database creation.
    • Implemented logic to handle a new --format option (realm, sqlite, all) to control database output.
    • Integrated the call to buildSqlite for SQLite generation.
    • Updated paths for CSV file processing to use the new renamed files.
    • Modified the default output path for the Realm database to temp_db/realm/.
  • src/models/RealmDataConst.ts
    • Updated SCHEMA_VERSION from 2 to 4.
    • Added a JSDoc comment explaining the purpose and relation of SCHEMA_VERSION to the app's CATALOG_DATA_SCHEMA_VERSION.
  • src/sqldelight/index.ts
    • Added new module containing the core logic for building SQLite databases.
    • Includes functions for opening/closing databases, applying DDL, parsing CSV data, and inserting records into SQLite tables.
    • Handles boolean to integer conversion for SQLite and writes commit ID files.
  • src/sqldelight/schemaDdl.ts
    • Added new utility module with functions to extract CREATE TABLE and CREATE INDEX statements from SqlDelight .sq files.
    • Provides functionality to write extracted DDL statements to a .sql file.
Activity
  • precisionmarks requested a summary of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

This 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 better-sqlite3 with SqlDelight schemas for efficient SQLite creation. This provides greater flexibility for downstream applications to consume the catalog data in their preferred format.

Highlights

  • SQLite Database Generation: Introduced the capability to build SQLite databases alongside the existing Realm databases, offering enhanced flexibility for data consumption.
  • Unified Database Build Process: Replaced the previous create_database.sh with a new build-databases.sh script, which can now generate both Realm and SQLite databases, with options to specify the desired output format.
  • Schema and Data Refinements: Renamed core CSV source files (e.g., RealmGunCatalog.csv to GunCatalog.csv), updated documentation, and incremented the internal SCHEMA_VERSION from 2 to 4. Specific data entries in GunCatalog.csv and ShootingRuleCatalog.csv were also refined, including new WFDA rules.
  • SqlDelight Integration: Added a new sqldelight directory containing SQL schema definitions and TypeScript logic for creating and populating SQLite databases using the better-sqlite3 library.
  • Improved Build Script Robustness: The scripts/create-database.sh script now includes a --no-git-check option to bypass untracked file checks and intelligently excludes generated database files from these warnings.
Changelog
  • .gitignore
    • Added temp_db/* to ignore temporary database files.
  • README.md
    • Updated the database creation command from create_database.sh to build-databases.sh.
    • Added a new section detailing output formats (realm, sqlite, all) and options for database generation.
    • Specified output paths for both Realm and SQLite databases and their commit ID files.
    • Updated references to CSV source files, removing 'Realm' prefix (e.g., RealmGunCatalog.csv to GunCatalog.csv).
    • Added examples for generating specific database formats.
  • build-databases.sh
    • Added new script to manage the creation of both Realm and SQLite databases.
    • Includes directory setup, calls to npm run create-database, and verification of generated database files.
  • create_database.sh
    • Removed, as its functionality is superseded by build-databases.sh.
  • db/realm/catalog_data.realm.commitid
    • Added a new commit ID file for the Realm database.
  • db/sqlite/catalog_data.db.commitid
    • Added a new commit ID file for the SQLite database.
  • db/sqlite/catalog_schema.sql
    • Added a new file containing auto-generated SQL DDL statements for catalog_metadata, guns, manufacturers, and shooting_rules tables, extracted from SqlDelight .sq files.
  • docs/GunCatalog.md
    • Updated the referenced CSV file name from source_data/RealmGunCatalog.csv to source_data/GunCatalog.csv.
    • Updated the manufacturerId field description to reference ManufacturerCatalog.csv.
  • docs/ManufacturerCatalog.md
    • Updated the referenced CSV file name from source_data/RealmManufacturerCatalog.csv to source_data/ManufacturerCatalog.csv.
  • docs/RealName.md
    • Added new documentation (in Japanese) discussing the addition of real firearm names to gun descriptions for improved searchability.
  • docs/ShootingRuleCatalog.md
    • Added new documentation for the ShootingRuleCatalog.csv schema, detailing fields, enum values for positions, gun types, sight types, and units of range.
  • docs/SqlDelightSupport.md
    • Added new documentation (in Japanese) outlining the plan and implementation hints for SqlDelight (SQLite3) data creation.
  • package-lock.json
    • Added better-sqlite3 and @types/better-sqlite3 as new dependencies.
  • package.json
    • Added better-sqlite3 and @types/better-sqlite3 to the project dependencies.
  • realm_data/catalog_data.realm.commitid
    • Removed old commit ID file, replaced by db/realm/catalog_data.realm.commitid.
  • scripts/create-database.sh
    • Introduced a --no-git-check option to bypass untracked file checks.
    • Modified the untracked files check to exclude files within the db/ directory.
  • source_data/GunCatalog.csv
    • Renamed from source_data/RealmGunCatalog.csv.
    • Updated description and descriptionJa fields for several gun entries (e.g., 'G17 CUSTOM', 'P320', 'G19 Gen.5 MOS') to include real firearm names.
  • source_data/ManufacturerCatalog.csv
    • Renamed from source_data/RealmManufacturerCatalog.csv.
  • source_data/ShootingRuleCatalog.csv
    • Renamed from source_data/RealmShootingRuleCatalog.csv.
    • Updated descriptions and range100x values for existing shooting rules.
    • Added new WFDA (World Fast Draw Association) rules for fast draw competitions.
  • sqldelight/catalog/CatalogMetadata.sq
    • Added new SQL schema definition for the catalog_metadata table.
  • sqldelight/catalog/Gun.sq
    • Added new SQL schema definition for the guns table, including an index on manufacturerId and a comprehensive search query.
  • sqldelight/catalog/Manufacturer.sq
    • Added new SQL schema definition for the manufacturers table, including a searchByKeyword query.
  • sqldelight/catalog/ShootingRule.sq
    • Added new SQL schema definition for the shooting_rules table.
  • src/createGunCatalog.ts
    • Updated the default file path for the gun catalog CSV to source_data/GunCatalog.csv.
  • src/createManufacturerCatalog.ts
    • Updated the default file path for the manufacturer catalog CSV to source_data/ManufacturerCatalog.csv.
  • src/createShootingRuleCatalog.ts
    • Updated the default file path for the shooting rule catalog CSV to source_data/ShootingRuleCatalog.csv.
  • src/index.ts
    • Imported buildSqlite function for SQLite database creation.
    • Implemented logic to handle a new --format option (realm, sqlite, all) to control database output.
    • Integrated the call to buildSqlite for SQLite generation.
    • Updated paths for CSV file processing to use the new renamed files.
    • Modified the default output path for the Realm database to temp_db/realm/.
  • src/models/RealmDataConst.ts
    • Updated SCHEMA_VERSION from 2 to 4.
    • Added a JSDoc comment explaining the purpose and relation of SCHEMA_VERSION to the app's CATALOG_DATA_SCHEMA_VERSION.
  • src/sqldelight/index.ts
    • Added new module containing the core logic for building SQLite databases.
    • Includes functions for opening/closing databases, applying DDL, parsing CSV data, and inserting records into SQLite tables.
    • Handles boolean to integer conversion for SQLite and writes commit ID files.
  • src/sqldelight/schemaDdl.ts
    • Added new utility module with functions to extract CREATE TABLE and CREATE INDEX statements from SqlDelight .sq files.
    • Provides functionality to write extracted DDL statements to a .sql file.
Activity
  • precisionmarks requested a summary of the pull request.

@precisionmarks
Copy link
Contributor

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

tinoue and others added 3 commits October 22, 2025 06:52
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…troducing a helper function to check for statement terminators
@tinoue
Copy link
Collaborator Author

tinoue commented Oct 22, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

Comment on lines +1 to +13
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
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If you apply the suggestion to rename the primary key to _id, this query will also need to be updated.

SELECT * FROM manufacturers WHERE _id = ?1;

Comment on lines +110 to 123
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"}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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"}`);

Comment on lines +46 to +48
`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)`
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
`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)`

Comment on lines +116 to +129
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)[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For robustness and cross-platform compatibility, it's better to use path.join() to construct file paths instead of string concatenation with path.normalize().

Suggested change
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)[];

@tinoue tinoue merged commit 70e8d3d into main Oct 22, 2025
1 check passed
@tinoue tinoue deleted the feat-sqldelight branch October 22, 2025 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants