D in accounting program

Adam D. Ruppe destructionator at gmail.com
Wed Nov 24 11:46:15 PST 2010


sybrandy wrote:
> Is there any chance we could see the code you wrote?

The majority of this app is a closed source proprietary thing
that I don't own the copyright on, but I was allowed to keep
most the helper libraries.

You can find most of it in here:
http://arsdnet.net/dcode/

cgi.d is for the cgi client applications and httpdconnection.d
shows a server, although that code is ancient and probably
doesn't even compile. (It requires the netman.d code - it
specializes the netman Connection class. Somewhere I have an
aim.d that works the same way too.)

cgi.d has two constructors: the default one follows the CGI
standard. The other one takes some raw data that should be
a HTTP request. It pulls everything out of it. (The benefit
of this is using my httpd program, I can construct a CGI object
and write client code in the same way as a traditional app.
I figure FastCGI should be able to be implemented in an identical
fashion but I haven't gotten around to it yet; performance
has been excellent so far, better than the old PHP was.)

import arsd.cgi;
import std.stdio; // required by cgi but not publically imported there
import std.string; // ditto

void main() {
     auto cgi = new Cgi;
     cgi.write("<html><body>Hello, world!</body></html>");
     cgi.close();
}


mysql.d wraps up just enough of the C mysql API for me to use
it here in a fairly sane fashion. It does queries with self-
implemented replacement and auto escaping. It returns a ranged
array of strings by default, or can do an assocative array.

(That is, it returns a MySql.Result range, where result.front
 is a string[] or a string[string]).

The client code is responsible for converting it to other
types. Pretty trivial thanks to std.conv so I like it this
way.

foreach(line; mysql.query("SELECT id, name FROM users")) {
     int id = to!int(line[0]);
     string name = line[1];
}

Alternatively:


foreach(line; mysql.query("SELECT id, name FROM users").byAssoc) {
     int id = to!int(line["id"]);
     string name = line["name"];
}


dom.d is the DOM implementation of course - nothing fancy there,
implementation wise.



web.d is a new thing I've been working on. The plan for it is
to do a stricter model/view separation and to automate a lot
of drudge work. (Regular cgi.d provides a much simpler interface,
the resulting code looks more like plain PHP.) You just
list functions and a fancy template mixin makes them available
to be called on the web interface. It works but is still too
incomplete/buggy to use on serious applications. I'm getting
there though.


More information about the Digitalmars-d mailing list