Re: New pre-processor interface added to Euphoria

new topic     » goto parent     » topic index » view thread      » older message » newer message

I just created the skeleton of another pre-processor. This one is a more advanced one and will not be included as a demo but hopefully it will be of use to people. It's called esql.

Here's what it does:

-- people.sql 
CREATE TABLE people ( 
  id integer primary key autoincrement, 
  first_name varchar(50) not null, 
  last_name varchar(50) not null, 
  age integer 
); 
 
CREATE INDEX people_name ON people(first_name, last_name); 
CREATE INDEX people_last_name ON people(last_name); 
CREATE INDEX people_age ON people(age); 

include esql_core.e as esql  
include people.sql as people 
 
esql:set_db("example.db") -- uses SQLite right now 
 
-- creates table if it does not already exist 
people:ensure_exists() 
 
-- automatically creates a type for the table contents and also a few creation 
-- functions 
people jim = people:empty() 
jim[people:first_name] = "Jim" 
jim[people:last_name] = "Doe" 
jim[people:age] = 30 
 
-- Saves the record to the database as automatically sets the ID 
jim = people:save(jim) 
 
people john = people:new(BLANK_ID, "John", "Doe", 33) 
john = people:save(john) 
 
-- Automatic 
object all_people = people:find_all() 
 
-- Created based on ID being a primary key 
object john_ = people:find_by_id(john[people:ID]) 
 
-- Created due to the index people_last_name 
object all_does = people:find_by_last_name("Doe") 
object all_dos = people:find_by_last_name("Do%", esql:LIKE) 
 
-- Created due to the index people_name 
object who_knows = people:find_by_name("John", "Doe") 
 
-- Automatic deleting by the primary key 
people:delete(john[people:ID]) 

All of this functionality exists right away to the Euphoria user by simply

include people.sql as people 

I'm pretty excited about all the possibilites of the pre-processor, in case you couldn't tell. Who knows what someone will come up with next.

Jeremy

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu