Reputation: 17930
are there any ways to perform the following queries in clojureql ? :
or is there any work around to running these ? even if I need another library to do it, that's fine.
Upvotes: 0
Views: 278
Reputation: 4173
ClojureQL is mainly for querying. There is some support for insert (conj! table records)
and delete (disj! table predicate)
, but the main thing it does is to provide an interface to SQL based on the relational operators project
,select
and rename
.
To do the queries you're asking for, you can drop into clojure.java.jdbc
, which ClojureQL uses under the hood.
First of all, the DDL commands can be done with help from the clojure.java.jdbc.ddl
namespace:
;; create table t1 (id int, name varchar(50), age varchar(100));
(execute! db
(create-table :t1
[:id :int]
[:name "VARCHAR(50)"]
[:age "VARCHAR(100)"])
;; drop table table3;
(execute! db
(drop-table :table3)
I don't think there's syntactic support for the other two operations you have there, but you can probably just send a raw query to the database like so.
(execute! db
["insert into table1(id, name, age) select id, name, age from table2"])
If you're doing a lot of migration/ddl-y type things, I think there are some libraries with a bit more syntactic support out there, because clojure.java.jdbc.ddl
"intentionally has a very minimal DDL syntax". (Perhaps Lobos or Ragtime?)
Upvotes: 1