class GetSQL

Overview

GetSQL provides functions for extracting meta-information from a databases in a generic fashion, and for making requests.

Included Modules

Defined in:

getsql.cr

Constant Summary

COLUMNS = {"sqlite3" => "SELECT name FROM pragma_table_info('%s')", "postgres" => "SELECT column_name FROM information_schema.columns WHERE table_name = '%s'"}
INDICES = {"sqlite3" => "SELECT sql FROM sqlite_schema WHERE type = 'index' AND tbl_name = '%s'", "postgres" => "SELECT indexdef FROM pg_indexes WHERE schemaname = 'public' AND tablename = '%s'"}

Each entry is a query to return 2-column rows, with the name of a table and the definition of an index.

JSON = MIME.from_extension(".json")

The default content type

TABLES = {"sqlite3" => "SELECT tbl_name FROM sqlite_schema WHERE type = 'table'", "postgres" => "SELECT table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema = 'public'"}

Each entry is a query to return single column rows with the names of all tables in a database.

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(connections = {} of String => String) #

[View source]

Class Method Detail

def self.column_type(uri : URI, table : String, column : String) #

[View source]
def self.columns(uri : URI, table : String) #

[View source]
def self.indices(uri : URI, table : String) #

[View source]
def self.ok?(uri : URI) #

True if and only if the database at the URI can be reached.


[View source]
def self.query(uri : URI, table : String, params : Enumerable(Tuple(String, String)) | Nil = nil, limit : Int = 1, offset : Int = 0) #

[View source]
def self.redacted(uri : URI | String) : URI #

Gets a redacted version of the URI (with the password obfuscated).


[View source]
def self.tables(uri : URI) #

[View source]
def self.where(params : Enumerable(Tuple(String, String)) | Nil) #

[View source]

Instance Method Detail

def add(name : String, uri : URI) #

Adds a new connection with the given name.


[View source]
def add(name : String, uri : String) #

Adds a new connection with the given name.


[View source]
def add(uri : URI) #

Adds a new connection named by the first element in the URI's path (excluding any file extension)


[View source]
def add(uri : String) #

Adds a new connection named by the first element in the URI's path (excluding any file extension)


[View source]
def call(context) #

[View source]
def database(name) #

[View source]
def databases #

[View source]
def indices(db : String, table : String) #

Gets the indices in the database, as a map of index definitions per table.


[View source]
def ok?(name : String) #

True if and only if the database at the URI corresponding to the given name can be reached.


[View source]
def query(db : String, table : String, params : Enumerable(Tuple(String, String)) | Nil = nil, limit : Int = 1, offset : Int = 0) #

[View source]
def remove(name : String) #

Removes the named connection, if it exists.


[View source]
def respond(context, &) #

[View source]
def tables(db : String) #

Gets the tables in the database specified by uri.


[View source]
def version #

[View source]