Skip to content
This repository has been archived by the owner on May 7, 2023. It is now read-only.

Commit

Permalink
Improve the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
synw committed Jul 21, 2019
1 parent d6157bb commit 9594020
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 30 deletions.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Welcome to Sqlcool's documentation!
:maxdepth: 2
:caption: Crud operations

schema.rst
init.rst
db_ops.rst
batch_ops.rst
Expand Down
30 changes: 0 additions & 30 deletions docs/init.rst
Original file line number Diff line number Diff line change
@@ -1,36 +1,6 @@
Initialize database
===================

Schema definition
-----------------

.. highlight:: dart

::

DbTable category = DbTable("category")..varchar("name", unique: true);
DbTable product = DbTable("product")
..varchar("name", unique: true)
..integer("price")
..real("number")
..text("description")
..foreignKey("category", onDelete: OnDelete.cascade)
..uniqueTogether("name", "number")
..index("name");

Parameters for the column constructors:

:name: *String* the name of the column

Optional parameters:

:unique: *bool* if the column must be unique
:nullable: *bool* if the column can be null
:defaultValue: *dynamic* (depending on the row type: integer if
the row is integer for example) the default value of a column

Note: the foreignKey must be placed after the other fields definitions

Initialize an empty database
----------------------------

Expand Down
82 changes: 82 additions & 0 deletions docs/schema.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
Schema definition
=================

Columns
-------

.. highlight:: dart

::

DbTable category = DbTable("category")..varchar("name", unique: true);
DbTable product = DbTable("product")
..varchar("name", unique: true)
..integer("price")
..real("number")
..boolean("bool", defaultValue: true)
..text("description")
..blob("blob")
..timestamp()
..foreignKey("category", onDelete: OnDelete.cascade);

Parameters for the column constructors:

:name: *String* the name of the column

Optional parameters:

:unique: *bool* if the column must be unique
:nullable: *bool* if the column can be null
:defaultValue: *dynamic* (depending on the row type: integer if
the row is integer for example) the default value of a column
:check: *String* a check constraint: ex:

::

DbTable("table")..integer("intname", check="intname>0");

Note: the foreignKey must be placed after the other fields definitions

Create an index on a column:

::

DbTable("table")
..varchar("name")
..index("name");

Unique together constraint:

::

DbTable("table")
..varchar("name")
..integer("number")
..uniqueTogether("name", "number");

Methods
-------

Initialize the database with a schema:

::

db.init(path: "mydb.sqlite", schema: <DbTable>[category, product]);

Check if the database has a schema:

::

final bool hasSchema = db.hasSchema() // true or false;

Get a table schema:

::

final DbTable productSchema = db.schema.table("product");

Check if a table is in the schema:

::

final bool tableExists = db.schema.hasTable("product");

0 comments on commit 9594020

Please sign in to comment.