Liking cljdoc? Tell your friends :D

parseq.core

Fully-resolved syntax trees for SQLite SQL.

Parses SQL through SQLite's own parser and name resolver (a vendored amalgamation with parse-coverage hooks) and returns unambiguous, machine-readable trees as plain Clojure data. Every column reference is resolved to its table, schema, cursor and column index; views and '*' are expanded the way SQLite itself resolves them; parse errors come back as data with byte offsets.

Quickstart:

(require '[parseq.core :as pq]) (pq/init! conn) ; any java.sql Connection to a SQLite db (pq/parse "SELECT b FROM t WHERE a > ?") (pq/refresh-schema!) ; after migrations on that connection

The explicit surface — (parser opts), (load-schema p schema), (parse p sql) — remains for juggling several parsers at once; init! installs one globally.

See README for the node reference and the exact resolution stage the dump reflects (post-resolution, pre-optimizer).

Fully-resolved syntax trees for SQLite SQL.

Parses SQL through SQLite's own parser and name resolver (a vendored
amalgamation with parse-coverage hooks) and returns unambiguous,
machine-readable trees as plain Clojure data. Every column reference
is resolved to its table, schema, cursor and column index; views and
'*' are expanded the way SQLite itself resolves them; parse errors
come back as data with byte offsets.

Quickstart:

  (require '[parseq.core :as pq])
  (pq/init! conn)          ; any java.sql Connection to a SQLite db
  (pq/parse "SELECT b FROM t WHERE a > ?")
  (pq/refresh-schema!)     ; after migrations on that connection

The explicit surface — (parser opts), (load-schema p schema),
(parse p sql) — remains for juggling several parsers at once;
init! installs one globally.

See README for the node reference and the exact resolution stage the
dump reflects (post-resolution, pre-optimizer).
raw docstring

closeclj

(close p)

Release the session. The parser is unusable afterwards. Idempotent.

Release the session. The parser is unusable afterwards. Idempotent.
sourceraw docstring

close!clj

(close!)

Close the parser installed by init! and forget its connection. Idempotent; explicit-handle parsers are unaffected.

Close the parser installed by init! and forget its connection.
Idempotent; explicit-handle parsers are unaffected.
sourceraw docstring

init!clj

(init! conn)
(init! conn opts)

Install conn as the schema source for the one-argument parse and return the parser. The connection's sqlite_schema is replayed into a fresh session; the connection is only ever read (here and on refresh-schema!) but must stay open until close!. Calling init! again closes the parser it replaces. opts are as for parser.

Install `conn` as the schema source for the one-argument parse and
return the parser. The connection's sqlite_schema is replayed into a
fresh session; the connection is only ever read (here and on
refresh-schema!) but must stay open until close!. Calling init!
again closes the parser it replaces. `opts` are as for parser.
sourceraw docstring

load-schemaclj

(load-schema p schema)

Load a schema into the session so subsequent parses resolve against it. schema is either a java.sql Connection to a SQLite database — its sqlite_schema DDL is read and replayed, and the connection is never written — or a string of DDL executed as-is. Returns nil on success or {:error "..."} when sqlite rejects the DDL. This is the only operation that touches database state (the session's own scratch database).

Load a schema into the session so subsequent parses resolve against
it. `schema` is either a java.sql Connection to a SQLite database —
its sqlite_schema DDL is read and replayed, and the connection is
never written — or a string of DDL executed as-is. Returns nil on
success or {:error "..."} when sqlite rejects the DDL. This is the
only operation that touches database state (the session's own
scratch database).
sourceraw docstring

parseclj

(parse sql)
(parse p sql)

Parse sql (one or more statements) and return the resolved tree:

{:sqlite "3.54.1" :statements [{:stmt {...} :sql "SELECT ..." :explain 0}]}

A statement that fails to parse appears as {:node :error :message ".." :offset 42}. Never throws for bad SQL; throws only for infrastructure failures (missing library, OOM). The one-argument form parses against the parser installed by init!.

Parse `sql` (one or more statements) and return the resolved tree:

  {:sqlite "3.54.1"
   :statements [{:stmt {...} :sql "SELECT ..." :explain 0}]}

A statement that fails to parse appears as
{:node :error :message ".." :offset 42}. Never throws for bad SQL;
throws only for infrastructure failures (missing library, OOM). The
one-argument form parses against the parser installed by init!.
sourceraw docstring

parserclj

(parser)
(parser opts)

Create a parser session.

Options: :impl :panama (FFM, needs a recent JVM) or :jni; the default is whichever binding loads on this JVM, FFM preferred :path SQLite database path (default ":memory:"). A file path resolves against that file's schema as opened; parsing never executes or mutates anything.

Parsing always happens in capture mode; nothing you parse here is executed. Use load-schema to make names resolvable.

Create a parser session.

Options:
  :impl  :panama (FFM, needs a recent JVM) or :jni; the default is
         whichever binding loads on this JVM, FFM preferred
  :path  SQLite database path (default ":memory:"). A file path
         resolves against that file's schema as opened; parsing
         never executes or mutates anything.

Parsing always happens in capture mode; nothing you parse here is
executed. Use load-schema to make names resolvable.
sourceraw docstring

refresh-schema!clj

(refresh-schema!)

Rebuild the installed parser's schema from the connection init! received, on a fresh native session. Unconditional: calling it is the explicit signal that the schema changed.

Rebuild the installed parser's schema from the connection init!
received, on a fresh native session. Unconditional: calling it is
the explicit signal that the schema changed.
sourceraw docstring

replay-schema!clj

(replay-schema! p conn)

Replay conn's schema into parser on a fresh native session, replacing whatever it held — schemas can shrink, and exec'd DDL cannot drop what an earlier replay created. Throws on a rejected replay. Workhorse of refresh-schema!.

Replay `conn`'s schema into `parser` on a fresh native session,
replacing whatever it held — schemas can shrink, and exec'd DDL
cannot drop what an earlier replay created. Throws on a rejected
replay. Workhorse of refresh-schema!.
sourceraw docstring

reset-handle!clj

(reset-handle! p new-h)

Swap in a fresh native handle (replay-schema! installs a fresh session through it). Closes the previous one. Internal.

Swap in a fresh native handle (replay-schema! installs a fresh
session through it). Closes the previous one. Internal.
sourceraw docstring

schema-ddlclj

(schema-ddl conn)

The CREATE statements of every object in conn's schema, concatenated in sqlite_schema order (tables and indexes interleaved the way SQLite stores them). This is the DDL load-schema replays for a connection.

The CREATE statements of every object in `conn`'s schema,
concatenated in sqlite_schema order (tables and indexes interleaved
the way SQLite stores them). This is the DDL load-schema replays
for a connection.
sourceraw docstring

sqlite-versionclj

(sqlite-version p)

SQLite version compiled into the native library.

SQLite version compiled into the native library.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close