Emacs: how to create yasnippets for different RDBMs in sql-interactive-mode -


i using sql-interactive-mode connect 2 databases: mysql , sqlite. created yasnippets mysql in yasnippets/sql-interactive-mode folder. example add column in mysql use following snippet:

# -*- mode: snippet -*- # name: add column # key: addcol # -- alter table $1 add column \`$2\` $3; 

but sqlite uses different syntax. how can create different yasnippets different databases?

as explained here can add arbitrary emacs lisp code (enclosed in backquotes) yasnippet snippets evaluated when expand. in sql-mode , sql-interactive-mode there variable called sql-product can check determine type of database (mysql, sqlite, postgres, etc.) working with.

that's need know. here example of how modify addcol snippet:

# ... alter table $1 `(if (eq sql-product 'mysql) "add" "frob")` column \`$2\` $3; 

this expand to

alter table $1 add column \`$2\` $3; 

for mysql and

alter table $1 frob column \`$2\` $3; 

for other types of databases.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -