Skip to content

Commit

Permalink
Update CQL syntax and struct definitions in docs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eliasjpr committed Aug 23, 2024
1 parent b1123c5 commit d7e74a3
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 41 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions docs/guides/active-record-with-cql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand All @@ -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?
Expand All @@ -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?
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/active-record-with-cql/belongsto.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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?
Expand Down
24 changes: 8 additions & 16 deletions docs/guides/active-record-with-cql/cql-record-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -68,10 +66,8 @@ end
### **Comment Model**

```crystal
struct Comment
include Cql::Record(Comment, Int64)
define AcmeDB, :comments
struct Comment <Cql::Record(Int64)
db_context AcmeDB, :comments
getter id : Int64?
getter post_id : Int64
Expand Down Expand Up @@ -278,10 +274,8 @@ end
### **Defining the Models**:

```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
Expand All @@ -294,10 +288,8 @@ struct Post
end
end
struct Comment
include Cql::Record(Comment, Int64)
define AcmeDB, :comments
struct Comment < Cql::Record(Int64)
db_context AcmeDB, :comments
getter id : Int64?
getter post_id : Int64
Expand Down
4 changes: 1 addition & 3 deletions docs/guides/active-record-with-cql/hasmany.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ Let’s db_context the `Post` and `Comment` models and establish the `HasMany` a
### **Post Model**

```crystal
struct Post< Cql::Record(Post, Int64)
struct Post < Cql::Record(Post, Int64)
db_context AcmeDB, :posts
getter id : Int64?
Expand All @@ -82,7 +81,6 @@ end

```crystal
struct Comment< Cql::Record(Comment, Int64)
db_context AcmeDB, :comments
getter id : Int64?
Expand Down
6 changes: 2 additions & 4 deletions docs/guides/active-record-with-cql/hasone.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ Let’s define the `User` and `Profile` models in CQL, establishing the `HasOne`
### **User Model**

```crystal
struct User< Cql::Record(User, Int64)
struct User< Cql::Record(Int64)
db_context AcmeDB, :users
getter id : Int64?
Expand All @@ -78,8 +77,7 @@ end
### **Profile Model**

```crystal
struct Profile< Cql::Record(Profile, Int64)
struct Profile < Cql::Record(Int64)
db_context AcmeDB, :profiles
getter id : Int64?
Expand Down
8 changes: 3 additions & 5 deletions docs/guides/active-record-with-cql/manytomany.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Let’s define the `Post`, `Tag`, and `PostTag` models in CQL, establishing the
### **Post Model**

```crystal
struct Post< Cql::Record(Post, Int64)
struct Post < Cql::Record(Int64)
db_context AcmeDB, :posts
getter id : Int64?
Expand All @@ -101,8 +101,7 @@ In the `Post` model, we define:
### **Tag Model**

```crystal
struct Tag< Cql::Record(Tag, Int64)
struct Tag < Cql::Record(Int64)
db_context AcmeDB, :tags
getter id : Int64?
Expand All @@ -126,8 +125,7 @@ Similarly, in the `Tag` model, we db_context:
### **PostTag Model (Join Table)**

```crystal
struct PostTag< Cql::Record(PostTag, Int64)
struct PostTag < Cql::Record(Int64)
db_context AcmeDB, :post_tags
getter id : Int64?
Expand Down
2 changes: 1 addition & 1 deletion src/foreign_key.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Cql
# **Example** Creating a new foreign key
#
# ```
# schema.build do
# Schema.define do
# table :users do
# column :id, Int32, primary: true
# column :name, String
Expand Down
2 changes: 1 addition & 1 deletion src/schema.cr
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ module Cql
# **Example**
#
# ```
# schema.build
# Schema.define
# ```
def build
@tables.each do |name, table|
Expand Down

0 comments on commit d7e74a3

Please sign in to comment.