From d7e74a3a2b49b57b6516f96f9a6b2e68569fbfcf Mon Sep 17 00:00:00 2001 From: eliasjpr Date: Fri, 23 Aug 2024 09:57:53 -0400 Subject: [PATCH] Update CQL syntax and struct definitions in docs Replaced `schema.build` with `Schema.define` across various documentation files to align with the updated API syntax. Simplified struct definitions by directly extending `Cql::Record` and removing redundant includes. These changes aim to improve clarity and maintain consistency with the latest library conventions. --- README.md | 4 ++-- docs/guides/active-record-with-cql/README.md | 10 +++----- .../active-record-with-cql/belongsto.md | 4 ++-- .../cql-record-models.md | 24 +++++++------------ docs/guides/active-record-with-cql/hasmany.md | 4 +--- docs/guides/active-record-with-cql/hasone.md | 6 ++--- .../active-record-with-cql/manytomany.md | 8 +++---- src/foreign_key.cr | 2 +- src/schema.cr | 2 +- 9 files changed, 23 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 0fb8ed7..e71af09 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ shards install Define the schema for your database tables: ```crystal -schema = Cql::Schema.build( +schema = Cql::Schema.define( :my_database, adapter: Cql::Adapter::Postgres, db: DB.open("postgresql://user:password@localhost:5432/database_name") @@ -137,7 +137,7 @@ user_repository.update(1, name: "Jane Smith") Work with your data using the Active Record pattern: ```crystal -AcmeDB = Cql::Schema.build(...) do ... end +AcmeDB = Cql::Schema.define(...) do ... end struct User < Cql::Record(Int64) db_context schema: AcmeDB, table: :users diff --git a/docs/guides/active-record-with-cql/README.md b/docs/guides/active-record-with-cql/README.md index a5570a8..00e06ab 100644 --- a/docs/guides/active-record-with-cql/README.md +++ b/docs/guides/active-record-with-cql/README.md @@ -102,8 +102,7 @@ Now that the schema is ready, we can define the `User` record (model) that maps ```crystal # src/models/user.cr - struct User - include Cql::Record(User, Int64) + struct User < Cql::Record(Int64) db_context AcmeDB, :users property id : Int64? @@ -156,7 +155,6 @@ CQL supports associations similar to ActiveRecord, Ecto, and other ORMs. Let's d # db/migrate/20230817000001_create_posts.cr class CreatePosts < Cql::Migration - schema.table :posts do primary text :title, null: false @@ -181,8 +179,7 @@ CQL supports associations similar to ActiveRecord, Ecto, and other ORMs. Let's d ```crystal # src/models/post.cr - struct Post - include Cql::Record(Post, Int64) + struct Post< Cql::Record(Int64) db_context AcmeDB, :posts property id : Int64? @@ -204,8 +201,7 @@ CQL supports associations similar to ActiveRecord, Ecto, and other ORMs. Let's d ```crystal # src/models/user.cr - class User - include Cql::Record(User, Int64) + struct User < Cql::Record(Int64) db_context AcmeDB, :users column id : Int64? diff --git a/docs/guides/active-record-with-cql/belongsto.md b/docs/guides/active-record-with-cql/belongsto.md index d1b1fb9..e490fbc 100644 --- a/docs/guides/active-record-with-cql/belongsto.md +++ b/docs/guides/active-record-with-cql/belongsto.md @@ -57,7 +57,7 @@ Next, we'll define the `Post` and `Comment` structs in CQL. ### **Post Model** ```crystal -Post < Cql::Record(Post, Int64) +struct Post < Cql::Record(Int64) db_context AcmeDB, :posts getter id : Int64? @@ -74,7 +74,7 @@ end ### **Comment Model** ```crystal -Comment < Cql::Record(Comment, Int64) +struct Comment < Cql::Record(Int64) db_context AcmeDB, :comments getter id : Int64? diff --git a/docs/guides/active-record-with-cql/cql-record-models.md b/docs/guides/active-record-with-cql/cql-record-models.md index 7e9960f..e94d020 100644 --- a/docs/guides/active-record-with-cql/cql-record-models.md +++ b/docs/guides/active-record-with-cql/cql-record-models.md @@ -49,10 +49,8 @@ Now, let's define the `Post` and `Comment` models that map to the `posts` and `c ### **Post Model** ```crystal -struct Post - include Cql::Record(Post, Int64) - - define AcmeDB, :posts +struct Post < Cql::Record(Int64) + db_context AcmeDB, :posts getter id : Int64? getter title : String @@ -68,10 +66,8 @@ end ### **Comment Model** ```crystal -struct Comment - include Cql::Record(Comment, Int64) - - define AcmeDB, :comments +struct Comment