Skip to content

Commit

Permalink
Added screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
epitron committed Nov 22, 2013
1 parent 4a576e1 commit 61df477
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 85 deletions.
Empty file modified .gitignore 100644 → 100755
Empty file.
13 changes: 13 additions & 0 deletions LICENSE
@@ -0,0 +1,13 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004

Copyright (C) 2004 Sam Hocevar
14 rue de Plaisance, 75014 Paris, France
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.
47 changes: 0 additions & 47 deletions README

This file was deleted.

36 changes: 36 additions & 0 deletions README.rdoc
@@ -0,0 +1,36 @@
= sqlsh

A shell for your SQL -- browse any kind of database, quickly and easily!

Brings familiar Unix commands (ls, mv, rm, etc.) and metaphors (pipes) to your SQL database.

http://chris.ill-logic.com/images/sqlsh.png

== Installing

gem install sqlsh

== Usage

=== First, load your database

Supply an URI:

sqlsh mysql://<username>:<password>@<hostname>/
sqlsh sqlite://databasefile.db

Or just a file (tries to intelligently guess the format):

sqlsh databasefile.db

=== Next, explore it

Just type "help" to see what you can do.

== Copyright

Copyright (c) 2005-2012 by Chris Gahan

== License

Licensed under the WTFPL2. (See LICENSE for details.)
67 changes: 29 additions & 38 deletions sqlsh.rb
Expand Up @@ -10,7 +10,11 @@
#
# Refactoring:
# ---------------------
# * Steal jed's display-in-colums thingy
# * Specs
# * Create a "query for information class" that abstracts over the different database types
# ^- then, use this to implement the interface
# * Use something like 'Slop'
# * Use Term::Table
# * Browser#for(path) returns a new browser in that path
# => ls("/what/lala") is implemented by @browser.for("/what/lala").ls
# => can all commands work without "use"?
Expand All @@ -31,7 +35,9 @@
# => "mkdir" or "new" command (creates databases, tables, and columns)
# => "mv" or "rename" (for table, column, etc.)
# => "edit <thing>" pops up a curses dialog w/ types and stuff (nano/vim/pico?)
# => "ls -l" shows {db: sizes/tables, table: columns/types/indexes, column: }.
# => "ls -l" shows {db: sizes/tables, table: columns/types/indexes, column: }.
# => args can be files or urls (intelligently guess which one the user means)
# => let the user open MySQL DB files directly (for MySQLi apps)
# => remember last connection and auto-connect next session
# => less-style results (scroll left/right/up/down)
# => make a reuslt object that can display in short (column)
Expand All @@ -45,37 +51,13 @@
# => compact table display mode (truncate) fields
# => use URI (or addressable) to parse uris
# => bookmarks
# => import/export databases (SQL, CSV, YAML, JSON, etc.)

###########################################################################
# Required modules
%w(rubygems sequel logger pp readline colorize).each{|mod| require mod}
###########################################################################



###########################################################################
# Helpers (aka. MonkeyPatches)
#
class Symbol
def to_proc
Proc.new { |*args| args.shift.__send__(self, *args) }
end
end

class String
def pad(n)
amount = [0,(n-size)].max # clip negative values to 0
self + ' '*amount
end

def startswith(sub)
(self =~ /^#{Regexp.escape(sub.to_s)}/) != nil
end
end

class Array
alias_method :filter, :select
end
require 'epitools'
require 'sequel'
require 'readline'
###########################################################################


Expand Down Expand Up @@ -135,6 +117,10 @@ def columns
@db[@table].columns.map(&:to_s).sort
end

def table_stats
table_stats_for(@db)
end

def use_table!(table)
if table_exists? table
@table = table.to_sym
Expand All @@ -156,7 +142,8 @@ def tables_for(dbname)
#
def table_stats_for(dbname)
results = {}
@db.fetch("SHOW TABLE STATUS FROM `#{dbname}`").map do |tbl|

@db.fetch("SHOW TABLE STATUS FROM `#{dbname}`").each do |tbl|
results[tbl[:Name]] = {
:data_size => tbl[:Data_length],
:index_size => tbl[:Index_length],
Expand All @@ -170,8 +157,9 @@ def table_stats_for(dbname)
:encoding => tbl[:Collation],
}
end

results
end


def database_size_for(dbname)
db_size = 0
Expand Down Expand Up @@ -204,6 +192,7 @@ def ls_l(params=nil)
when :tables
# tables w/ rows, index size, etc.
nil

when :databases
# database size, table count, etc.
list = databases.map { |dbname| [dbname, {:tables=>tables_for(dbname).size}] }
Expand Down Expand Up @@ -243,9 +232,9 @@ def column_type(column)
end

TRANSLATE_TO_SQL_COLUMN_TYPE = {
"int" => "INTEGER",
"string" => "VARCHAR(255)",
"str" => "VARCHAR(255)",
"int" => "INTEGER",
"string" => "VARCHAR(255)",
"str" => "VARCHAR(255)",
}

def mv(src, dest)
Expand Down Expand Up @@ -339,7 +328,7 @@ def ls_color


def completions(sub)
ls.filter{|x| x.startswith(sub) }
ls.select{|x| x.startswith(sub) }
end

end
Expand Down Expand Up @@ -399,10 +388,10 @@ def column_print(things, color=:white)
things += [''] * (cols - (things.size % cols))
end

things.map!{|thing| thing.pad(col_width)}
things.map!{|thing| thing.ljust(col_width)}

things.each_slice(cols) do |slice|
puts slice.join(' | ').colorize(color)
puts slice.join(' | ').send(color)
end
end

Expand Down Expand Up @@ -438,6 +427,8 @@ def parse(line)
@browser.mv($1, $2)
when /^cd (\S+)/i
@browser.cd($1)
when ".."
@browser.cd("..")
when /^rm -r (\S+)/i
@browser.rm_r($1)
when /^rm (\S+)/i
Expand Down

0 comments on commit 61df477

Please sign in to comment.