Skip to content

Commit acc4a0b

Browse files
committed
Improve documentation
1 parent 3345655 commit acc4a0b

6 files changed

+75
-17
lines changed

.jsdoc.config.json

+24-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,29 @@
99
},
1010
"opts": {
1111
"encoding": "utf8",
12-
"destination": "./documentation/"
12+
"destination": "./documentation/",
13+
"readme": "documentation_index.md",
14+
"template": "./node_modules/clean-jsdoc-theme",
15+
"theme_opts": {
16+
"title": "sql.js",
17+
"meta": [
18+
"<meta name=\"author\" content=\"Ophir Lojkine\">",
19+
"<meta name=\"description\" content=\"sql.js technical documentation\">"
20+
],
21+
"menu": [
22+
{
23+
"title": "Website",
24+
"link": "https://sql.js.org/"
25+
},
26+
{
27+
"title": "Github",
28+
"link": "https://github.com/sql-js/sql.js"
29+
},
30+
{
31+
"title": "Demo",
32+
"link": "https://sql.js.org/examples/GUI/"
33+
}
34+
]
35+
}
1336
}
1437
}

README.md

+15-14
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ sql.js can be used like any traditional JavaScript library. If you are building
1515
SQLite is public domain, sql.js is MIT licensed.
1616

1717
## API documentation
18-
A [full API documentation](https://sql.js.org/documentation/class/Database.html) generated from comments inside the source code is available.
18+
A [full API documentation](https://sql.js.org/documentation/) for all the available classes and methods is available.
19+
Is is generated from comments inside the source code, and is thus always up to date.
1920

2021
## Usage
2122

@@ -37,19 +38,6 @@ var db = new SQL.Database();
3738
// NOTE: You can also use new SQL.Database(data) where
3839
// data is an Uint8Array representing an SQLite database file
3940

40-
// Execute some sql
41-
sqlstr = "CREATE TABLE hello (a int, b char);";
42-
sqlstr += "INSERT INTO hello VALUES (0, 'hello');"
43-
sqlstr += "INSERT INTO hello VALUES (1, 'world');"
44-
db.run(sqlstr); // Run the query without returning anything
45-
46-
var res = db.exec("SELECT * FROM hello");
47-
/*
48-
[
49-
{columns:['a','b'], values:[[0,'hello'],[1,'world']]}
50-
]
51-
*/
52-
5341
// Prepare an sql statement
5442
var stmt = db.prepare("SELECT * FROM hello WHERE a=:aval AND b=:bval");
5543

@@ -65,6 +53,19 @@ stmt.free();
6553
// You can not use your statement anymore once it has been freed.
6654
// But not freeing your statements causes memory leaks. You don't want that.
6755

56+
// Execute a single SQL string that contains multiple statements
57+
sqlstr = "CREATE TABLE hello (a int, b char);";
58+
sqlstr += "INSERT INTO hello VALUES (0, 'hello');"
59+
sqlstr += "INSERT INTO hello VALUES (1, 'world');"
60+
db.run(sqlstr); // Run the query without returning anything
61+
62+
var res = db.exec("SELECT * FROM hello");
63+
/*
64+
[
65+
{columns:['a','b'], values:[[0,'hello'],[1,'world']]}
66+
]
67+
*/
68+
6869
// You can also use JavaScript functions inside your SQL code
6970
// Create the js function you need
7071
function add(a, b) {return a+b;}

documentation_index.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# sql.js API documentation
2+
3+
## Introduction
4+
5+
If you need a quick intoduction with code samples that you can copy-and-paste,
6+
head over to [sql.js.org](https://sql.js.org/)
7+
8+
## API
9+
10+
### The initSqlJs function
11+
12+
The root object in the API is the [`initSqlJs`](./global.html#initSqlJs) function,
13+
that takes an [`SqlJsConfig`](./global.html#SqlJsConfig) parameter,
14+
and returns an [SqlJs](./global.html#SqlJs) object
15+
16+
### The SqlJs object
17+
18+
`initSqlJs` returns the main sql.js object, the [**`SqlJs`**](./module-SqlJs.html) module, which contains :
19+
20+
#### Database
21+
22+
[**Database**](./Database.html) is the main class, that represents an SQLite database.
23+
24+
#### Statement
25+
26+
The [**Statement**](./Statement.html) class is used for prepared statements.

package-lock.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"url": "https://github.com/sql-js/sql.js/issues"
4141
},
4242
"devDependencies": {
43+
"clean-jsdoc-theme": "^2.2.14",
4344
"eslint": "^6.8.0",
4445
"eslint-config-airbnb-base": "^14.2.0",
4546
"eslint-plugin-import": "^2.22.1",

src/api.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
"use strict";
2424

2525
/**
26-
* @typedef {{Database:Database}} SqlJs
27-
* @property {Database} Database the database constructor
26+
* @typedef {{Database:Database, Statement:Statement}} SqlJs
27+
* @property {Database} Database A class that represents an SQLite database
28+
* @property {Statement} Statement The prepared statement class
2829
*/
2930

3031
/**

0 commit comments

Comments
 (0)