Class: SyntaxTree::Database::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/database.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_connection) ⇒ Connection

Returns a new instance of Connection.



279
280
281
# File 'lib/syntax_tree/database.rb', line 279

def initialize(raw_connection)
  @raw_connection = raw_connection
end

Instance Attribute Details

#raw_connectionObject (readonly)

Returns the value of attribute raw_connection.



277
278
279
# File 'lib/syntax_tree/database.rb', line 277

def raw_connection
  @raw_connection
end

Instance Method Details

#execute(query, binds = []) ⇒ Object



283
284
285
# File 'lib/syntax_tree/database.rb', line 283

def execute(query, binds = [])
  raw_connection.execute(query, binds)
end

#index_file(filepath) ⇒ Object



287
288
289
290
# File 'lib/syntax_tree/database.rb', line 287

def index_file(filepath)
  program = SyntaxTree.parse(SyntaxTree.read(filepath))
  program.accept(IndexingVisitor.new(self, filepath))
end

#last_insert_row_idObject



292
293
294
# File 'lib/syntax_tree/database.rb', line 292

def last_insert_row_id
  raw_connection.last_insert_row_id
end

#prepareObject



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/syntax_tree/database.rb', line 296

def prepare
  raw_connection.execute("    CREATE TABLE nodes (\n      id integer primary key,\n      type varchar(20),\n      path varchar(200),\n      line integer,\n      column integer\n    );\n  SQL\n\n  raw_connection.execute(<<~SQL)\n    CREATE INDEX nodes_type ON nodes (type);\n  SQL\n\n  raw_connection.execute(<<~SQL)\n    CREATE TABLE edges (\n      id integer primary key,\n      from_id integer,\n      to_id integer,\n      name varchar(20),\n      list_index integer\n    );\n  SQL\n\n  raw_connection.execute(<<~SQL)\n    CREATE INDEX edges_name ON edges (name);\n  SQL\nend\n")

#search(query) ⇒ Object



326
327
328
# File 'lib/syntax_tree/database.rb', line 326

def search(query)
  QueryResult.new(self, Pattern.new(query).compile)
end