C Roff XSLT JavaScript HTML CSS Other
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
LICENSE.md
Makefile
README.md
TODO.md
archive.xml
atom-template.xml
audit-example.txt
audit.c
audit.css
audit.html
audit.js
comments.c
compats.c
configure
db.fr.xml
db.old.txt
db.txt
extern.h
header.c
index-fig1.dot
index-fig2.dot
index-fig3.dot
index-fig5.dot
index-fig6.dot
index.css
index.dot
index.xml
javascript.c
kwbp.vim
kwebapp-audit-gv.1
kwebapp-audit-json.1
kwebapp-audit.1
kwebapp-c-header.1
kwebapp-c-source.1
kwebapp-javascript.1
kwebapp-sql.1
kwebapp-sqldiff.1
kwebapp-xliff.1
kwebapp.1
kwebapp.5
linker.c
main.c
mandoc.css
notugly.xsl
parser.c
printer.c
protos.c
source.c
sql.c
test.c
test.xml
tests.c
versions.xml
writer.c
xliff.c

README.md

Introduction

kwebapp translates business logic of a database application---objects and queries---into C, SQL (SQLite), and JavaScript code. The business logic is given as a configuration file, for example:

struct user {
  field name text null comment "full name (or null)";
  field email text unique comment "unique e-mail";
  field hash password comment "hashed password";
  field id int rowid comment "unique identifier";
  search id: comment "search by user identifier";
  search email,password: name creds comment "lookup by credentials";
  comment "a system user";
};
struct session {
  field user struct uid;
  field uid:user.id int comment "user bound to session";
  field token int comment "unique session token";
  field id int rowid;
  comment "web session";
};

This configuration is then translated into a C API (header file and implementation) and an SQL schema or update sequence. The API consists of "getters", "setters", updaters, and deleters; and is implemented in straight-forward C code you link directly into your application.

The generated files currently use ksql(3) to wrap around SQLite and (optionally) kcgi(3) for JSON or validation output.

You will need the newest library version to use kwebapp. All of these tools are built in tandem.

Why is kwebapp handy? It removes a lot of "boilerplate" code querying the database and allocating objects. Some more features:

  • Functions generated for modifying (updates), allocating (inserts), and accessing (queries).
  • Automagic foreign key "INNER JOIN" when accessing structures. You specify nested structures in your configuration file, and kwebapp creates the "join" functionality when querying for those objects.
  • Several types of accessors: iterator-based (function callback), list-based (queue), and unique (selecting on unique fields).
  • Well-formed, readable C and SQL output describing functions (if applicable), variables, structures, and so on.
  • "Difference calculator" between configuration files helps database updates be reasonable by providing the necessary "ALTER TABLE" and so on to help with versioning. (Also protects against accidental incompatible changes.)
  • Beyond the usual native type support (int, text, real, blob), also supports "password" type that has automatic hashing mechanism built-in during selection from and insertion into the database.
  • Several different types of SQL query (and update and delete) operators.
  • Optional JSON output functions.
  • Optional field validation (kcgi(3)) functions.

See the TODO for what still needs to be done.

This repository mirrors the main repository on BSD.lv. It is still very much under development!

License

All sources use the ISC (like OpenBSD) license. See the LICENSE.md file for details.