0.0.26 • Published 4 years ago

ts-sqlite-generator v0.0.26

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

ts-sqlite-generator

install packages

yarn add -D ts-sqlite-generator typescript 

checkout example and run it

See example folder. Clone this repo and run 'yarn example'

prepare interface

have at least one interface with doc tag @sqlite_entry. This tag indicates that this interface should be able to be inserted without any referencing foreign keys. For example in src/store/models.ts:

/**
 * @sqlite_entry.
 */
interface Phase {
  name: string;
  phaseId: number;
  articles: Article[];
  optionalFieldsWork?: boolean;
}

interface Article {
  articleId: number;
  title: string;
  /**
   * @sqlite_index
   *
   */
  url: string;
  content: string;
  type: ArticleType;
  position: ArticlePosition;
  compoundType: CompoundType;
}

enum ArticleType {
  A,
  B,
  C
}

type ArticlePosition = "left" | "center" | "right";

interface SubTypeA {
  a: string;
}

interface SubTypeB {
  b: string;
}

type CompoundType = SubTypeA | SubTypeB;

create schema generator script

add a script file, for example 'scripts/generateSchemas.ts':

import path from 'path';
import { generator } from 'ts-sqlite-generator typescript';

generator(
  [path.join(__dirname, "models.ts")],
  path.join(__dirname, "../tsconfig.json"),
  path.join(__dirname, "__generated__/schema.ts"),
  path.join(__dirname, "__generated__/helpers.ts")
);

run with ts-node

yarn ts-node -T scripts/generateSchemas.ts

output

this results in queries being generated (CREATE TABLE, INSERT, REPLACE)

0.0.25

4 years ago

0.0.26

4 years ago

0.0.23

4 years ago

0.0.24

4 years ago

0.0.22

4 years ago

0.0.20

4 years ago

0.0.21

4 years ago

0.0.19

4 years ago

0.0.18

4 years ago

0.0.17

4 years ago

0.0.16

4 years ago

0.0.15

4 years ago

0.0.13

4 years ago

0.0.14

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.5

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.4

4 years ago

0.0.1

4 years ago