0.0.26 • Published 5 years ago

ts-sqlite-generator v0.0.26

Weekly downloads
2
License
MIT
Repository
github
Last release
5 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

5 years ago

0.0.26

5 years ago

0.0.23

5 years ago

0.0.24

5 years ago

0.0.22

5 years ago

0.0.20

5 years ago

0.0.21

5 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.13

5 years ago

0.0.14

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.5

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.4

5 years ago

0.0.1

5 years ago