Skip to content

Commit

Permalink
Merge pull request #4 from snacks02/pascal
Browse files Browse the repository at this point in the history
Change type names to PascalCase
  • Loading branch information
eliasjpr authored Sep 23, 2024
2 parents d112c6b + 11334d9 commit 1ba4af2
Show file tree
Hide file tree
Showing 52 changed files with 256 additions and 256 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/crystal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
apt-get install -y sqlite3 libsqlite3-dev
- name: Verify SQLite installation
run: sqlite3 --version
- name: Create Sqlite databases
- name: Create SQLite databases
run: |
touch ./spec/db/northwind.db
touch ./spec/db/data.db
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ CQL Toolkit is a powerful library designed to simplify and enhance the managemen

- **Query Builder**: Programmatically create complex SQL queries.
- **Insert, Update, Delete Operations**: Perform CRUD operations with ease.
- **Repository Pattern**: Manage your data more effectively using `Cql::Repository(T)`.
- **Active Record Pattern**: Work with your data models using `Cql::Record(T)`.
- **Repository Pattern**: Manage your data more effectively using `CQL::Repository(T)`.
- **Active Record Pattern**: Work with your data models using `CQL::Record(T)`.

## Installation

Expand All @@ -56,9 +56,9 @@ shards install
Define the schema for your database tables:

```crystal
schema = Cql::Schema.define(
schema = CQL::Schema.define(
:my_database,
adapter: Cql::Adapter::Postgres,
adapter: CQL::Adapter::Postgres,
db: DB.open("postgresql://user:password@localhost:5432/database_name")
) do
Expand All @@ -75,7 +75,7 @@ end
With the schema in place, you can start executing queries:

```crystal
q = Cql::Query.new(schema)
q = CQL::Query.new(schema)
user = q.from(:users).where(id: 1).first(as: User)
Expand All @@ -87,7 +87,7 @@ puts user.name if user
Insert new records into the database:

```crystal
q = Cql::Query.new(schema)
q = CQL::Query.new(schema)
q.insert_into(:users, name: "Jane Doe", email: "[email protected]")
```
Expand All @@ -97,7 +97,7 @@ q.insert_into(:users, name: "Jane Doe", email: "[email protected]")
Update existing records:

```crystal
q = Cql::Query.new(schema)
q = CQL::Query.new(schema)
q.update(:users).set(name: "Jane Smith").where(id: 1)
```
Expand All @@ -107,7 +107,7 @@ q.update(:users).set(name: "Jane Smith").where(id: 1)
Delete records from the database:

```crystal
q = Cql::Query.new(schema)
q = CQL::Query.new(schema)
q.delete_from(:users).where(id: 1)
```
Expand All @@ -117,7 +117,7 @@ q.delete_from(:users).where(id: 1)
Utilize the repository pattern for organized data management:

```crystal
user_repository = Cql::Repository(User, Int64).new(schema, :users)
user_repository = CQL::Repository(User, Int64).new(schema, :users)
# Create a new user
user_repository.create(id: 1, name: "Jane Doe", email: "[email protected]")
Expand All @@ -139,9 +139,9 @@ user_repository.update(1, name: "Jane Smith")
Work with your data using the Active Record pattern:

```crystal
AcmeDB = Cql::Schema.define(...) do ... end
AcmeDB = CQL::Schema.define(...) do ... end
struct User < Cql::Record(Int64)
struct User < CQL::Record(Int64)
db_context schema: AcmeDB, table: :users
# Crystal properties (no macros)
Expand Down
2 changes: 1 addition & 1 deletion spec/adapters/postgres_schema_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct UserPref
end
end

describe Cql::Schema do
describe CQL::Schema do
context "handles json fields" do
Example.table :user_pref do
primary
Expand Down
2 changes: 1 addition & 1 deletion spec/adapters/sqlite_schema_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../spec_helper"

describe Cql::Schema do
describe CQL::Schema do
column_exists = ->(col : Symbol, table : Symbol) do
begin
query = "SELECT 1 FROM pragma_table_info('#{table}') WHERE name = '#{col}';\n"
Expand Down
2 changes: 1 addition & 1 deletion spec/delete_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def d
Northwind.delete
end

describe Cql::Delete do
describe CQL::Delete do
it "Delete specific rows that meet a certain condition." do
delete_query = d.from(:users)
.where { users.id == 1 }
Expand Down
2 changes: 1 addition & 1 deletion spec/insert_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "./spec_helper"

describe Cql::Insert do
describe CQL::Insert do
it "creates Insert Into query" do
insert_query = Northwind.insert.into(:users).values(name: "John", email: "[email protected]").to_sql

Expand Down
8 changes: 4 additions & 4 deletions spec/migration_spec.cr
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
require "./spec_helper"
require "./migrations/*"

describe Cql::Migration do
describe CQL::Migration do
migrator = Northwind.migrator

after_all do
File.delete("spec/db/northwind.db")
end

it "has a migration" do
Cql::Migrator.migrations.size.should eq(2)
CQL::Migrator.migrations.size.should eq(2)
end

it "migrates up" do
Expand All @@ -31,7 +31,7 @@ describe Cql::Migration do
migrator.rollback

migrator.last.try(&.version).should eq(nil)
migrator.applied_migrations.map(&.version).should eq([] of Cql::Migrator::MigrationRecord)
migrator.applied_migrations.map(&.version).should eq([] of CQL::Migrator::MigrationRecord)
end

it "redo" do
Expand Down Expand Up @@ -63,6 +63,6 @@ describe Cql::Migration do
it "prints pending migrations" do
migrator.down
migrator.print_pending_migrations
migrator.pending_migrations.should be_a(Array(Cql::BaseMigration.class))
migrator.pending_migrations.should be_a(Array(CQL::BaseMigration.class))
end
end
2 changes: 1 addition & 1 deletion spec/migrations/alter_users_migration_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AlterUsersMigration < Cql::Migration(987654321)
class AlterUsersMigration < CQL::Migration(987654321)
def up
schema.alter :users do
add_column :phone, String
Expand Down
2 changes: 1 addition & 1 deletion spec/migrations/create_users_migration_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateUsersMigration < Cql::Migration(123456789)
class CreateUsersMigration < CQL::Migration(123456789)
def up
schema.users.create!
end
Expand Down
6 changes: 3 additions & 3 deletions spec/query_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "./spec_helper"

describe Cql::Query do
describe CQL::Query do
describe "Basic SELECT queries" do
it "selects all columns from tables" do
select_query = Northwind.query.from(:customers, :users).to_sql
Expand Down Expand Up @@ -240,7 +240,7 @@ describe Cql::Query do

describe "Indexes" do
it "Creates indexes for table" do
index = Cql::Index.new(Northwind.tables[:users], [:name, :email], unique: true)
index = CQL::Index.new(Northwind.tables[:users], [:name, :email], unique: true)

output = <<-SQL
CREATE UNIQUE INDEX idx_name_emai ON users (name, email)
Expand All @@ -250,7 +250,7 @@ describe Cql::Query do
end

it "Creates non-unique index for table" do
index = Cql::Index.new(Northwind.tables[:orders], [:customer_id, :order_date], unique: false)
index = CQL::Index.new(Northwind.tables[:orders], [:customer_id, :order_date], unique: false)

output = <<-SQL
CREATE INDEX idx_cust_orde ON orders (customer_id, order_date)
Expand Down
12 changes: 6 additions & 6 deletions spec/record_spec.cr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require "./spec_helper"

AcmeDB = Cql::Schema.define(
AcmeDB = CQL::Schema.define(
:acme_db,
adapter: Cql::Adapter::Postgres,
adapter: CQL::Adapter::Postgres,
uri: ENV["DATABASE_URL"]) do
table :posts do
primary :id, Int64, auto_increment: true
Expand All @@ -18,7 +18,7 @@ AcmeDB = Cql::Schema.define(
end
end

struct Post < Cql::Record(Int64)
struct Post < CQL::Record(Int64)
db_context AcmeDB, :posts

getter id : Int64?
Expand All @@ -30,7 +30,7 @@ struct Post < Cql::Record(Int64)
end
end

struct Comment < Cql::Record(Int64)
struct Comment < CQL::Record(Int64)
db_context AcmeDB, :comments

getter id : Int64?
Expand All @@ -41,7 +41,7 @@ struct Comment < Cql::Record(Int64)
end
end

describe Cql::Record do
describe CQL::Record do
AcmeDB.posts.create!
AcmeDB.comments.create!

Expand Down Expand Up @@ -70,7 +70,7 @@ describe Cql::Record do
.limit(1)
.order(published_at: :desc)

query.should be_a Cql::Query
query.should be_a CQL::Query
end
end

Expand Down
14 changes: 7 additions & 7 deletions spec/relations_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "./spec_helper"

AcmeDB2 = Cql::Schema.define(:acme_db, adapter: Cql::Adapter::Postgres, uri: ENV["DATABASE_URL"]) do
AcmeDB2 = CQL::Schema.define(:acme_db, adapter: CQL::Adapter::Postgres, uri: ENV["DATABASE_URL"]) do
table :movies do
primary :id, Int64, auto_increment: true
text :title
Expand Down Expand Up @@ -30,7 +30,7 @@ AcmeDB2 = Cql::Schema.define(:acme_db, adapter: Cql::Adapter::Postgres, uri: ENV
end
end

struct Actor < Cql::Record(Int64)
struct Actor < CQL::Record(Int64)
db_context AcmeDB2, :actors

getter id : Int64?
Expand All @@ -40,7 +40,7 @@ struct Actor < Cql::Record(Int64)
end
end

struct Movie < Cql::Record(Int64)
struct Movie < CQL::Record(Int64)
db_context AcmeDB2, :movies

has_one :screenplay, Screenplay
Expand All @@ -54,7 +54,7 @@ struct Movie < Cql::Record(Int64)
end
end

struct Director < Cql::Record(Int64)
struct Director < CQL::Record(Int64)
db_context AcmeDB2, :directors

getter id : Int64?
Expand All @@ -65,7 +65,7 @@ struct Director < Cql::Record(Int64)
end
end

struct Screenplay < Cql::Record(Int64)
struct Screenplay < CQL::Record(Int64)
db_context AcmeDB2, :screenplays

belongs_to :movie, foreign_key: :movie_id
Expand All @@ -77,7 +77,7 @@ struct Screenplay < Cql::Record(Int64)
end
end

struct MoviesActors < Cql::Record(Int64)
struct MoviesActors < CQL::Record(Int64)
db_context AcmeDB2, :movies_actors

getter id : Int64?
Expand All @@ -90,7 +90,7 @@ struct MoviesActors < Cql::Record(Int64)
end
end

describe Cql::Relations do
describe CQL::Relations do
before_each do
AcmeDB2.movies.create!
AcmeDB2.screenplays.create!
Expand Down
4 changes: 2 additions & 2 deletions spec/repository_spec.cr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require "./spec_helper"

Users = Cql::Repository(User, Int32).new(Billing, :users)
Users = CQL::Repository(User, Int32).new(Billing, :users)

describe Cql::Repository(User, Int32) do
describe CQL::Repository(User, Int32) do
Billing.users.create!

before_each do
Expand Down
4 changes: 2 additions & 2 deletions spec/schemas/billing_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Billing = Cql::Schema.define(
Billing = CQL::Schema.define(
name: :billing,
adapter: Cql::Adapter::Sqlite,
adapter: CQL::Adapter::SQLite,
uri: "sqlite3://spec/db/billing.db") do
table :users do
primary :id, Int32
Expand Down
4 changes: 2 additions & 2 deletions spec/schemas/data_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Data = Cql::Schema.define(
Data = CQL::Schema.define(
:data,
adapter: Cql::Adapter::Sqlite,
adapter: CQL::Adapter::SQLite,
uri: "sqlite3://spec/db/data.db") do
table :customers do
primary :id, Int32
Expand Down
4 changes: 2 additions & 2 deletions spec/schemas/example_spec.cr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require "pg"

Example = Cql::Schema.define(
Example = CQL::Schema.define(
:example,
adapter: Cql::Adapter::Postgres,
adapter: CQL::Adapter::Postgres,
uri: ENV["DATABASE_URL"]) do
table :customers, as: "cust" do
primary :customer_id, Int64, auto_increment: true
Expand Down
4 changes: 2 additions & 2 deletions spec/schemas/northwind_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Northwind = Cql::Schema.define(
Northwind = CQL::Schema.define(
name: :northwind,
adapter: Cql::Adapter::Sqlite,
adapter: CQL::Adapter::SQLite,
uri: "sqlite3://spec/db/northwind.db") do
table :customers do
primary :id, Int32
Expand Down
4 changes: 2 additions & 2 deletions spec/schemas/tabledb_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TableDB = Cql::Schema.define(
TableDB = CQL::Schema.define(
name: :tabledb,
adapter: Cql::Adapter::Sqlite,
adapter: CQL::Adapter::SQLite,
uri: "sqlite3://spec/db/tabledb.db") do
table :customers do
primary :id, Int32
Expand Down
2 changes: 1 addition & 1 deletion spec/table_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "./spec_helper"

describe Cql::Table do
describe CQL::Table do
it "creates table" do
TableDB.customers.drop!
TableDB.customers.create!
Expand Down
2 changes: 1 addition & 1 deletion spec/update_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "./spec_helper"

describe Cql::Update do
describe CQL::Update do
it "creates Update query" do
update_query = Northwind.update.table(:users)
.set(name: "John", email: "[email protected]")
Expand Down
Loading

0 comments on commit 1ba4af2

Please sign in to comment.