Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into pascal
Browse files Browse the repository at this point in the history
  • Loading branch information
snacks02 committed Sep 23, 2024
2 parents 8f7e84d + d112c6b commit 11334d9
Show file tree
Hide file tree
Showing 29 changed files with 249 additions and 239 deletions.
Binary file removed .DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions .ameba.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Documentation/DocumentationAdmonition:
Enabled: false

Lint/NotNil:
Enabled: false
3 changes: 2 additions & 1 deletion .github/workflows/crystal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ jobs:
run: sqlite3 --version
- name: Create SQLite databases
run: |
mkdir -p ./spec/db
touch ./spec/db/northwind.db
touch ./spec/db/data.db
touch ./spec/db/billing.db
Expand All @@ -57,6 +56,8 @@ jobs:
run: shards install
- name: Check code style
run: crystal tool format --check
- name: Check code linting with Ameba
run: bin/ameba
- name: Run tests
env:
DATABASE_URL: postgres://example:example@postgres:5432/example
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/.shards/
*.dwarf
/.vscode/
/.DS_Store/
.DS_Store
/spec/db/*.db
# Libraries don't need dependency lock
# Dependencies will be locked in applications that use them
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,11 @@ Contributions are welcome! To contribute:

1. Fork this repository.
2. Create your feature branch: `git checkout -b my-new-feature`.
3. Commit your changes: `git commit -am 'Add some feature'`.
4. Push to the branch: `git push origin my-new-feature`.
5. Create a new Pull Request.
3. Start Postgres: `docker run --rm -e POSTGRES_DB=spec -e POSTGRES_PASSWORD=password -p 5432:5432 postgres`.
4. Run specs: `DATABASE_URL="postgres://postgres:password@localhost:5432/spec" crystal spec`.
5. Commit your changes: `git commit -am 'Add some feature'`.
6. Push to the branch: `git push origin my-new-feature`.
7. Create a new Pull Request.

## License

Expand Down
4 changes: 3 additions & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: cql
version: 0.0.108
version: 0.0.121
authors:
- Elias Perez <[email protected]>
crystal: '>= 1.12.2'
Expand All @@ -12,6 +12,8 @@ dependencies:
tallboy:
github: epoch/tallboy
development_dependencies:
ameba:
github: crystal-ameba/ameba
sqlite3:
github: crystal-lang/crystal-sqlite3
mysql:
Expand Down
Empty file added spec/db/.keep
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions spec/table_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe CQL::Table do

customer = CustomerModel.new(1, "John", "New York", 100)

insert_query = TableDB.insert.into(:customers).values(
TableDB.insert.into(:customers).values(
id: customer.id,
name: customer.name,
city: customer.city,
Expand Down Expand Up @@ -40,7 +40,7 @@ describe CQL::Table do
count_query = TableDB.query.from(:customers).count
count_query.first!(as: Int32).should eq 2

result = TableDB.delete.from(:customers).commit
TableDB.delete.from(:customers).commit
count_query.first!(as: Int32).should eq 0
end

Expand All @@ -50,7 +50,7 @@ describe CQL::Table do
check_query = "SELECT name FROM sqlite_master WHERE type='table' AND name='#{table}'"

expect_raises(DB::NoResultsError) do
name = TableDB.db.query_one(check_query, as: String)
TableDB.db.query_one(check_query, as: String)
end
end
end
Binary file removed src/.DS_Store
Binary file not shown.
8 changes: 4 additions & 4 deletions src/alter_table.cr
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,15 @@ module CQL
# sql = to_sql(visitor)
# ```
def to_sql(visitor : Expression::Visitor)
String::Builder.build do |sb|
String.build do |string|
@actions.each do |action|
case action
when Expression::CreateIndex, Expression::DropIndex, Expression::RenameTable
sb << action.accept(visitor)
string << action.accept(visitor)
else
sb << Expression::AlterTable.new(@table, action).accept(visitor)
string << Expression::AlterTable.new(@table, action).accept(visitor)
end
sb << ";\n"
string << ";\n"
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions src/dialects/mysql_dialect.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ module Expression
end

def auto_increment_primary_key(column : CQL::BaseColumn, col_type : String) : String
String::Builder.build do |sb|
sb << column.name
sb << " "
sb << col_type
sb << " PRIMARY KEY"
sb << " AUTO_INCREMENT" if column.auto_increment?
String.build do |string|
string << column.name
string << " "
string << col_type
string << " PRIMARY KEY"
string << " AUTO_INCREMENT" if column.auto_increment?
end
end

Expand Down
14 changes: 7 additions & 7 deletions src/dialects/postgres_dialect.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ module Expression
end

def auto_increment_primary_key(column : CQL::BaseColumn, col_type : String) : String
String::Builder.build do |sb|
sb << column.name
sb << " "
sb << col_type
sb << " GENERATED"
sb << " ALWAYS" if column.auto_increment?
sb << " AS IDENTITY PRIMARY KEY"
String.build do |string|
string << column.name
string << " "
string << col_type
string << " GENERATED"
string << " ALWAYS" if column.auto_increment?
string << " AS IDENTITY PRIMARY KEY"
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/dialects/sqlite_dialect.cr
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module Expression
end

def drop_foreign_key(table_name : String, constraint_name : String) : String
message = <<-MSG
<<-MSG
SQLite does not support dropping foreign keys directly via the ALTER TABLE
statement. You need to recreate the table without the foreign key constraint.
Expand Down
24 changes: 12 additions & 12 deletions src/expression/aggregator_builder.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@ module Expression
def initialize(@aggregate_function : Condition)
end

def >(value : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, ">", value))
def >(other : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, ">", other))
end

def <(value : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, "<", value))
def <(other : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, "<", other))
end

def >=(value : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, ">=", value))
def >=(other : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, ">=", other))
end

def <=(value : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, "<=", value))
def <=(other : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, "<=", other))
end

def ==(value : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, "=", value))
def ==(other : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, "=", other))
end

def !=(value : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, "!=", value))
def !=(other : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, "!=", other))
end
end
end
Loading

0 comments on commit 11334d9

Please sign in to comment.