Skip to content

Active record #6

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

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open

Active record #6

wants to merge 46 commits into from

Conversation

eliasjpr
Copy link
Contributor

@eliasjpr eliasjpr commented Apr 2, 2025

This pull request introduces several new test suites for the CQL ORM library, focusing on various aspects of the Active Record pattern implementation. The changes include adding tests for attributes, callbacks, deletions, and insertions. Below is a summary of the most important changes:

New Test Suites Added:

  • Attributes Tests:

    • Added tests for the attributes method to ensure it returns a hash of attributes and handles setting attributes correctly.
  • Callbacks Tests:

    • Added tests for callback registration, execution order, and halting mechanisms to ensure callbacks are executed in the correct order and can halt operations when necessary.
  • Deletable Tests:

    • Added tests for the delete! and delete_by! methods to verify that records can be deleted by ID or specific criteria, and that callbacks are triggered correctly during deletions.
  • Insertable Tests:

    • Added tests for the create! method to ensure new records are created correctly, including handling validation errors and setting attributes.

Project Configuration:

  • Windsurf Rules:
    • Added a .windsurfrules file outlining the project's focus on Crystal programming language, PostgreSQL compatibility, and adherence to SOLID principles.

eliasjpr and others added 30 commits March 21, 2025 10:11
…Schema. Enhance table management and query execution features, including support for SQLite and PostgreSQL URIs. Add functionality for dumping schema structure to a file and improve error logging for database operations.
…ctive_record module with enhanced functionality for model definitions, querying, and associations. This refactor includes the addition of attributes, callbacks, and validations, streamlining the ORM capabilities for better usability and maintainability.
…s, callbacks, insertable, and updateable modules. Implement validations for user models and enhance error handling. This update improves the overall robustness and reliability of the ORM functionality.
…ord deletion by ID, field matching, and all records deletion. Implement error handling for non-existent records and nil IDs. Enhance callback execution during deletion processes.
…ibute handling, callback execution, and validation processes. Update tests for insertable, updateable, and queryable functionalities to ensure consistency and reliability across the ORM framework.
…nt using a new attributes method. Update tests to directly verify user attributes after updates, enhancing clarity and reducing redundancy in the test suite.
…tion in the relations module. Add tests for the Post model to verify user associations, including creation, updating, and deletion of associated users. Update queryable tests to reflect changes in grouping functionality. Additionally, introduce a new posts table in the schema for improved data handling.
…move unused code and enhance callback tracking functionality. Add tests for has_one, has_many, and many_to_many associations, ensuring proper creation, deletion, and retrieval of associated records. Update schema to support new models and relationships, improving overall ORM capabilities.
The commit adds comprehensive error handling and moves SQL formatting logic to dialect classes. It introduces a new error hierarchy and standardizes SQL
…de changes you'd like me to summarize in a commit message.
This commit introduces new database schema files and refactors the dialect classes to enhance structure and maintainability. It includes the addition of a base dialect class that consolidates common functionalities across different database dialects, improving code organization and readability. Additionally, the JSON column method in the table class has been updated to support custom types, and various dialect implementations have been adjusted to inherit from the new base class.
This commit removes the returning clause from DELETE and INSERT SQL queries for consistency. It introduces a method to retrieve the current timestamp function based on the database dialect, improving timestamp handling across different database types. Additionally, the initialization of the Expression generator has been simplified to directly use the adapter's dialect method.
This commit removes the old CustomerModel spec file and introduces a new implementation with default values for properties. Additionally, it updates the current timestamp method in MySQL, PostgreSQL, and SQLite dialects to return a formatted timestamp string, improving consistency in timestamp handling across different database types.
This commit updates the DATABASE_URL in the .env file for improved security by removing the username from the connection string. Additionally, it enhances the .windsurfrules file by formatting the content into a more structured format with comments for better readability. Minor whitespace adjustments were made in schema files and the CustomerModel spec file to maintain consistency.
This commit updates the CustomerModel by assigning default values to the city and balance properties, as well as the created_at and updated_at timestamps. The initialize method has been reformatted for improved readability while maintaining functionality.
…unused test files

This commit updates the DATABASE_URL in the .env file by removing the username for improved security. The .windsurfrules file is reformatted with comments for better readability. Additionally, it removes the unused test_schema.db and test.db files to clean up the project structure.
This commit modifies the user update spec to assert that the result is a TestUser instance after an update. Additionally, it cleans up the SQLite dialect by removing an unnecessary warning log for the DROP COLUMN workaround, streamlining the code while maintaining functionality.
This commit introduces the ability to define foreign key constraints in table definitions, enhancing the CQL::Table class with methods to add foreign keys. It also updates the SQL generation process to include foreign key definitions in CREATE TABLE statements across different dialects. Additionally, comprehensive tests for foreign key operations have been added to ensure correct functionality and error handling for mismatched column counts.
This commit updates the foreign key definition syntax in the schema specifications for both PostgreSQL and SQLite, aligning it with the new method signature. It also enhances the documentation for the foreign key method in the alter_table module, clarifying parameter usage and providing examples. Additionally, it ensures that default names are generated for foreign keys when not explicitly provided, improving usability and consistency across the codebase.
This commit introduces the ability to define unique and check constraints within table definitions in the CQL::Table class. It adds methods for creating unique and check constraints, enhancing the SQL generation process to include these constraints in CREATE TABLE statements across different dialects. Comprehensive tests have been added to validate the functionality of these new features, ensuring correct behavior and error handling.
eliasjpr and others added 16 commits April 7, 2025 20:10
This commit modifies the migration version handling in the CQL::Migration module by changing the type from Int64 to Int32 for applied migrations. It also enhances the rollback method to utilize database transactions, ensuring that rolled back migrations are accurately tracked and printed. Additionally, a default version value is introduced in the BaseMigration class, along with a method to enforce version definition in subclasses, improving overall migration management.
This commit introduces a new project.mdc file that outlines the rules and guidelines for using the Crystal programming language (v1.15.1) and adhering to SOLID principles in software design. It includes a description of the CQL (Crystal Query Language) ORM library, highlighting its key features such as type safety, macro-powered DSL, and support for major relational databases. This addition aims to provide clarity and direction for developers working on the project.
This commit introduces several enhancements to the CQL (Crystal Query Language) library. It adds foreign key definitions in the Northwind schema, ensuring proper relationships between tables. Additionally, the query handling has been improved to support string aliases for tables and columns, enhancing the flexibility of query construction. The changes also include updates to the query methods to accept both string and symbol types, improving usability and consistency across the codebase. Comprehensive tests have been added to validate these new features and ensure correct functionality.
This commit updates the DATABASE_URL in the .env file to use 'postgres' as the username for improved security. Additionally, it adds a note in the project.mdc file regarding the limitations of the Crystal programming language in dynamically creating symbols. The query_spec.cr file has been updated to ensure SQL queries are formatted correctly, including adjustments to WHERE clauses and JOIN conditions for clarity. Furthermore, the table_spec.cr file now uses Int64 for count queries to ensure consistency across the codebase.
…consistency

This commit enhances the clarity of the query and table specifications by adjusting formatting and comments throughout the codebase. Changes include consistent spacing in join conditions, improved alias handling in query methods, and refined comments for better understanding. Additionally, unnecessary lines have been removed to streamline the code, contributing to overall maintainability.
This commit introduces a new CQL::DB::JSONBConverter module to manage JSON data conversion between database result sets and JSON format. The UserPref struct has been updated to utilize this new converter, enhancing the handling of JSON preferences. Additionally, the import statements in cql.cr have been adjusted to include the new converters directory, ensuring proper module loading.
This commit introduces a new .tool-versions file specifying Crystal version 1.15.1 for consistent development environments. Additionally, the obsolete structure.sql file has been removed, streamlining the project and eliminating unnecessary files. Various adjustments have been made to improve code organization and clarity across the codebase.
…alHelpers

This commit removes an unnecessary blank line in the CQL::Column documentation for improved clarity. Additionally, it refactors the assignment of the table property in the InternalHelpers module to use a more concise syntax, enhancing code readability. These changes contribute to a cleaner and more maintainable codebase.
This commit updates the CQL::Schema.define method to require an adapter parameter, enhancing clarity and ensuring that the correct database adapter is explicitly specified during schema initialization. Corresponding changes have been made in the schema_spec tests to reflect this new requirement, improving the robustness of the schema setup process.
This commit reorganizes the spec files by consolidating helper requirements and removing obsolete spec_helper files. It introduces new test files for migration, query, schema, and table functionalities, significantly improving test coverage for the CQL library. Additionally, it implements a custom password validator and various model specifications, ensuring robust validation and callback mechanisms. These changes contribute to a more structured and maintainable testing environment, enhancing the overall quality of the codebase.
This commit improves the record retrieval methods in the CQL::ActiveRecord::Queryable module by adding new tests for the .find! and .find? methods. The .find! method now raises a CQL::Schema::ConnectionError instead of DB::NoResultsError during connection issues, with a plan to revert this once the underlying schema is fixed. The .find? method has been updated to utilize the .find method for consistency. Additionally, new tests ensure that records can be found by ID and attributes, enhancing overall test coverage and reliability of the queryable functionality.
This commit refines the query specifications in the CQL library by updating the error handling in the CQL::Schema and CQL::ActiveRecord::Queryable modules. The .find! and .find_by! methods now consistently raise DB::NoResultsError instead of CQL::Schema::ConnectionError, improving clarity in error reporting. Additionally, the SQL query generation in query_spec.cr has been adjusted for better formatting, ensuring that the generated SQL statements are accurate and maintainable. These changes contribute to a more robust and user-friendly query interface.
…ation in CQL

This commit introduces several key enhancements to the CQL::ActiveRecord module. It adds methods for loading associations, including has_many, belongs_to, has_one, and many_to_many, improving the functionality of the ORM. Additionally, a new macro for registering relation metadata has been implemented, allowing for better management of defined relations. The movie model has been updated to include a blank line for clarity, and various database files have been updated to reflect changes in the schema. These improvements contribute to a more robust and user-friendly ActiveRecord interface.
…tory

This commit modifies the .gitignore file to change the exclusion pattern for database files from /spec/db/*.db to spec/support/db/*.db. This adjustment ensures that only the intended database files in the support directory are ignored, improving project organization and clarity.
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.

1 participant