lib/baza/driver/pg/table.rb in baza-0.0.35 vs lib/baza/driver/pg/table.rb in baza-0.0.36

- old
+ new

@@ -7,11 +7,11 @@ @name = @data.fetch(:table_name) end def drop @db.with_database(database_name) do - @db.query("DROP TABLE \"#{@db.escape_table(name)}\"") + @db.query("DROP TABLE #{@db.quote_table(name)}") end end def data ret = { @@ -70,11 +70,11 @@ raise Baza::Errors::ColumnNotFound, "Column not found: #{name}" unless column column end def truncate - @db.query("TRUNCATE #{@db.sep_table}#{@db.escape_table(name)}#{@db.sep_table} RESTART IDENTITY") + @db.query("TRUNCATE #{@db.quote_table(name)} RESTART IDENTITY") self end def foreign_keys(args = {}) sql = " @@ -162,11 +162,11 @@ def create_indexes(index_list, args = {}) db.indexes.create_index(index_list, args.merge(table_name: name)) end def rename(new_name) - @db.query("ALTER TABLE #{@db.sep_table}#{@db.escape_table(name)}#{@db.sep_table} RENAME TO #{@db.sep_table}#{@db.escape_table(new_name)}#{@db.sep_table}") + @db.query("ALTER TABLE #{@db.quote_table(name)} RENAME TO #{@db.quote_table(new_name)}") @name = new_name.to_s self end def reload @@ -182,17 +182,17 @@ self end def rows_count @db.databases.with_database(database_name) do - sql = "SELECT COUNT(*) AS count FROM #{@db.sep_table}#{@db.escape_table(name)}#{@db.sep_table}" + sql = "SELECT COUNT(*) AS count FROM #{@db.quote_table(name)}" return @db.query(sql).fetch.fetch(:count).to_i end end def optimize - @db.query("VACUUM #{@db.sep_table}#{@db.escape_table(name)}#{@db.sep_table}") + @db.query("VACUUM #{@db.quote_table(name)}") self end def clone(newname, _args = {}) raise "Invalid name." if newname.to_s.strip.empty? @@ -218,28 +218,28 @@ end private def clone_insert_from_original_table(newname, columns_list) - sql_clone = "INSERT INTO #{@db.sep_table}#{@db.escape_table(newname)}#{@db.sep_table} (" + sql_clone = "INSERT INTO #{@db.quote_table(newname)} (" first = true columns_list.each do |column_data| sql_clone << "," unless first first = false if first - sql_clone << "#{@db.sep_col}#{@db.escape_column(column_data.fetch(:name))}#{@db.sep_col}" + sql_clone << @db.quote_column(column_data.fetch(:name)) end sql_clone << ") SELECT " first = true columns_list.each do |column_data| sql_clone << "," unless first first = false if first - sql_clone << "#{@db.sep_col}#{@db.escape_column(column_data.fetch(:name))}#{@db.sep_col}" + sql_clone << @db.quote_column(column_data.fetch(:name)) end - sql_clone << " FROM #{@db.sep_table}#{@db.escape_table(name)}#{@db.sep_table}" + sql_clone << " FROM #{@db.quote_table(name)}" @db.query(sql_clone) end end