Skip to content

Commit a5bf0ae

Browse files
committed
Add simple boot script (boot.q) to easily initialise kdb-common in a kdb process
1 parent 0f577fa commit a5bf0ae

File tree

2 files changed

+74
-20
lines changed

2 files changed

+74
-20
lines changed

README.md

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,27 @@ All the details related to this library can be found on the wiki:
99
To use the functionality within this repository straight away:
1010

1111
1. Download the latest version, extract and `cd` into the root folder
12-
1. Run `q src/require.q`
13-
1. `.require.init[]`
12+
1. Start kdb+ with `boot.q`:
13+
* Linux: `q $(pwd)/boot.q`
14+
* Windows: `q %CD%/boot.q`
1415

15-
You can then load any of the libraries within the repository by using the `.require.lib` function with the library name. For example, to load `log.q`, type ``.require.lib `log``.
16+
This initialisation script will load the `cargs` and `log` libraries automatically during boot. Additional libraries can be loaded via the `--load-libs` command line argument, or once the process is booted with the `.require.lib` function.
17+
18+
See the [require.q wiki page](https://github.com/BuaBook/kdb-common/wiki/require.q) for more information.
1619

1720
### Example Output
1821

19-
```q
20-
C:\Users\jasra_000\git\kdb-common>%QHOME%\w32\q src/require.q
21-
KDB+ 3.4 2016.10.10 Copyright (C) 1993-2016 Kx Systems
22-
w32/ 4()core 4095MB jasra_000 jase6230 10.1.0.249 NONEXPIRE
23-
24-
q).require.init[]
25-
Require library initialised [ Root: :C:\Users\jasra_000\git\kdb-common ]
26-
Library root location refreshed [ File Count: 29 ]
27-
q).require.lib `log
28-
Loading library: `log
29-
Loading C:\Users\jasra_000\git\kdb-common/src/log.q
30-
Loading library: `util
31-
Loading C:\Users\jasra_000\git\kdb-common/src/util.q
32-
Loading library: `type
33-
Loading C:\Users\jasra_000\git\kdb-common/src/type.q
22+
```bash
23+
> rlwrap $QHOME/l64/q $(pwd)/boot.q
24+
...
25+
Application root: /home/jas/git/kdb-common | kdb-common root: /home/jas/git/kdb-common
26+
Library root location refreshed [ File Count: 61 ]
27+
...
3428
Library initialisation function detected [ Func: .log.init ]
29+
Binding implementations to library interfaces [ Library: log ] [ Interfaces: 6 ]
3530

36-
Logging enabled [ Level: INFO ]
31+
Logging enabled [ Level: INFO ] [ Logger: .log.loggers.basic ] [ Formatter: .log.formatter.default ]
3732

38-
2017.03.07 10:47:30.381 INFO pid-6644 jasra_000 0 Initialised library: `log
33+
2021.11.04 08:58:26.877 INFO pid-727 jas 0 Initialised library: log
3934
q)
4035
```

boot.q

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Simple Process Initialisation - kdb-common
2+
// Copyright (c) 2021 Jaskirat Rajasansir
3+
4+
// Provides a simple initialisation of kdb-common with require and core libraries
5+
6+
7+
/ Environment variable to change the root that 'require' will initialise and search for libraries from. If this is not
8+
/ set, it will be the folder that 'boot.q' is specified from. If it is specified, 'require' is assumed to be
9+
/ available at *boot.q-dir*/src/require.q
10+
.boot.cfg.appRootEnvVar:`KDB_APPLICATION_ROOT;
11+
12+
/ Commmand line argument to automatically load any additional libraries (comma separated) during initialisation
13+
.boot.cfg.loadLibsCmdArg:`$"load-libs";
14+
15+
/ The libraries that are always loaded
16+
.boot.cfg.coreLibs:`log`cargs;
17+
18+
19+
/ The root path of the kdb-common libraries
20+
.boot.root.kdbCommon:`:.
21+
22+
/ The root path of the application. This will only be different from '.boot.root.kdbCommon' if $KDB_APPLICATION_ROOT is set
23+
.boot.root.app:`:.;
24+
25+
26+
/ The command line arguments parsed with '.cargs.getWithInternal'
27+
.boot.args:(`symbol$())!();
28+
29+
30+
.boot.init:{
31+
.boot.root[`kdbCommon`app]:first ` vs hsym .z.f;
32+
33+
envRoot:getenv .boot.cfg.appRootEnvVar;
34+
35+
if[0 < count envRoot;
36+
.boot.root.app:`$":",envRoot;
37+
];
38+
39+
-1 "Application root: ",(1_ string .boot.root.app)," | kdb-common root: ",1_ string .boot.root.kdbCommon;
40+
41+
require:` sv .boot.root.kdbCommon,`src`require.q;
42+
system "l ",1_ string require;
43+
44+
.require.init .boot.root.app;
45+
.require.lib each .boot.cfg.coreLibs;
46+
47+
.boot.args,:.cargs.getWithInternal[];
48+
49+
if[.boot.cfg.loadLibsCmdArg in key .boot.args;
50+
additionalLibs:`$"," vs .boot.args .boot.cfg.loadLibsCmdArg;
51+
52+
if[0 < count additionalLibs except `;
53+
.require.lib each additionalLibs;
54+
];
55+
];
56+
};
57+
58+
59+
.boot.init[];

0 commit comments

Comments
 (0)