Skip to content

Commit

Permalink
trying to build gem without bundler
Browse files Browse the repository at this point in the history
  • Loading branch information
ianic committed Jan 4, 2012
1 parent 6e9cd47 commit 139d489
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 22 deletions.
1 change: 1 addition & 0 deletions .bundle/config
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
---
BUNDLE_DISABLE_SHARED_GEMS: '1'
BUNDLE_BIN: bin
12 changes: 6 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ gemspec
# gem "activesupport", "3.1.1"
# gem "ZenTest"

# group :test do
# gem 'minitest', '>=2.7.0'
# gem 'ZenTest'
# gem 'autotest-growl'
# gem 'autotest-fsevent'
# end
group :test do
gem 'minitest', '>=2.7.0'
gem 'ZenTest'
gem 'autotest-growl'
gem 'autotest-fsevent'
end

12 changes: 5 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ PATH
remote: .
specs:
mssql (0.0.1)
activesupport (~> 3.1.1)
hashie (~> 1.0.0)
tiny_tds (~> 0.5.0)

GEM
remote: http://rubygems.org/
remote: http://gems.minus5.hr/
remote: https://rubygems.org/
specs:
ZenTest (4.6.2)
activesupport (3.1.1)
activesupport (3.1.3)
multi_json (~> 1.0)
autotest-fsevent (0.2.5)
sys-uname
autotest-growl (0.2.14)
hashie (1.0.0)
minitest (2.7.0)
multi_json (1.0.3)
multi_json (1.0.4)
sys-uname (0.8.6)
tiny_tds (0.5.0)

Expand All @@ -25,10 +26,7 @@ PLATFORMS

DEPENDENCIES
ZenTest
activesupport (= 3.1.1)
autotest-fsevent
autotest-growl
hashie (= 1.0.0)
minitest (>= 2.7.0)
mssql!
tiny_tds (= 0.5.0)
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,16 @@ In the following examples I will use pubs database which is often installed by S


## Emacs usage


I build this for use with Emacs sql-mode. Add /emacs/sql_ms.el to your init.el:

(add-to-list 'load-path "~/Work/mssql/emacs/")
(require 'sql-ms)

Create ~/.mssql file with connections you want to use.
In Emacs press F12 or M-x enter-db-mode to open two buffers: \*queries\* and \*SQL\*. Write your queries in queries buffer and watch results in SQL buffer.

Keybindings:

* Ctrl-c c - sends region from queries to SQL buffer
* Ctrl-c b - sends whole buffer
16 changes: 16 additions & 0 deletions bin/mssql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'mssql' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require 'rubygems'
require 'bundler/setup'

load Gem.bin_path('mssql', 'mssql')
7 changes: 0 additions & 7 deletions bin/mssql.rb

This file was deleted.

120 changes: 120 additions & 0 deletions emacs/sql-ms.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
(require 'sql)

(defcustom sql-conn ""
"Default mssql connection."
:type 'string
:group 'SQL
:safe 'stringp)

;; customize ms sql mode
(setq sql-ms-program "mssql.rb")
(setq sql-ms-options '())
(setq sql-ms-login-params '(conn))

(defun my-sql-comint-ms (product options)
"Create comint buffer and connect to Microsoft SQL Server."
;; Put all parameters to the program (if defined) in a list and call
;; make-comint.
(setq sql-conn
(sql-get-login-ext "Connection: " sql-conn nil nil)
)
(let ((params options))
(if (not (string= "" sql-conn))
(setq params (append (list "-c" sql-conn) params)))
(sql-comint product params)))

(sql-set-product-feature 'ms :sqli-comint-func 'my-sql-comint-ms)

;;sql mode hooks
(add-hook 'sql-mode-hook (lambda ()
(setq truncate-lines t)
(sql-highlight-ms-keywords)
(setq sql-send-terminator t)
(setq comint-process-echoes t)
(setq tab-width 2)))
(add-hook 'sql-interactive-mode-hook (lambda ()
(setq truncate-lines t)
(setq comint-process-echoes t)
(text-scale-decrease 1)))

;; opening sql buffers
(defvar db-buffer "queries")
(defsubst db-get-buffer () (concat "*" db-buffer "*"))

(defun enter-db-mode ()
(interactive)
(sql-ms)
(delete-other-windows)
(split-window-horizontally)
(switch-to-buffer-other-window (db-get-buffer) t)
(sql-mode)
;(sql-highlight-ms-keywords)
(swap-windows)
(other-window -1)
)

(global-set-key [f12] 'enter-db-mode)

(sql-set-product-feature 'ms :list-all ".find")
(sql-set-product-feature 'ms :list-table ".explain %s")
(sql-set-product-feature 'ms :prompt-regexp "^\\w*> ")
(sql-set-product-feature 'ms :completion-object 'sql-ms-completion-object)
(sql-set-product-feature 'ms :completion-column 'sql-ms-completion-object)

(defun sql-ms-completion-object (sqlbuf schema)
(sql-redirect-value
(sql-find-sqli-buffer)
(concat
"select s.name + '.' + o.name"
" from sys.objects o"
" inner join sys.schemas s on o.schema_id = s.schema_id"
" where"
" type in ('P', 'V', 'U', 'TF', 'IF', 'FN' )"
" and is_ms_shipped = 0"
"\ngo"
)
"^| \\([a-zA-Z0-9_\.]+\\).*|$" 1)
)

;;fixing a function from sql.el
(defun sql-try-completion (string collection &optional predicate)
(when sql-completion-sqlbuf
(with-current-buffer sql-completion-sqlbuf
(let ((schema (and (string-match "\\`\\(\\sw\\(:?\\sw\\|\\s_\\)*\\)[.]" string)
(downcase (match-string 1 string)))))

;; If we haven't loaded any object name yet, load local schema
(unless sql-completion-object
(sql-build-completions nil))

;; If they want another schema, load it if we haven't yet
(when schema
(let ((schema-dot (concat schema "."))
(schema-len (1+ (length schema)))
(names sql-completion-object)
has-schema)

(while (and (not has-schema) names)
(setq has-schema (and
(>= (length (car names)) schema-len)
(string= schema-dot
(downcase (substring (car names)
0 schema-len))))
names (cdr names)))
(unless has-schema
(sql-build-completions schema)))))

(cond
((not predicate)
(try-completion string sql-completion-object))
((eq predicate t)
(all-completions string sql-completion-object))
((eq predicate 'lambda)
(test-completion string sql-completion-object))
;;ianic added this condition
((eq predicate 'metadata)
(test-completion string sql-completion-object))
((eq (car predicate) 'boundaries)
(completion-boundaries string sql-completion-object nil (cdr predicate)))))))

(provide 'sql-ms)
3 changes: 2 additions & 1 deletion lib/mssql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
require 'pp'

require 'rubygems'
require "bundler/setup"
#require "bundler/setup"

require 'tiny_tds'
require 'hashie'
require 'active_support/core_ext/hash/keys.rb'
Expand Down
2 changes: 2 additions & 0 deletions mssql.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Gem::Specification.new do |gem|
gem.homepage = "http://www.minus5.hr"

gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
#gem.executables = "mssql"
gem.files = `git ls-files`.split("\n")
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
gem.name = "mssql"
Expand All @@ -17,6 +18,7 @@ Gem::Specification.new do |gem|

gem.add_dependency('tiny_tds' , '~> 0.5.0')
gem.add_dependency('hashie' , '~> 1.0.0')
#gem.add_dependency('multi_json' , '~> 1.0.3')
gem.add_dependency('activesupport' , '~> 3.1.1')
# gem.add_dependency('ZenTest' , '~> 4.6.2')
# gem.add_dependency('minitest' , '~> 2.7.0')
Expand Down

0 comments on commit 139d489

Please sign in to comment.