1.5.1 • Published 5 months ago

@soyamiruku/typed-surql v1.5.1

Weekly downloads
-
License
Apache 2.0
Repository
github
Last release
5 months ago

How To Use

# Clone this repository
$ git clone https://github.com/soya-miruku/typed-surql
 ensure you have enabled the following in your tsconfig file:
  "emitDecoratorMetadata": true,
  "experimentalDecorators": true,
# Or Using Deno
import {TypedSurQL} from 'https://deno.land/x/typed_surql@v1.1.4/mod.ts';
# Or npm/bun
import { TypedSurQL } from '@soyamiruku/typed-surl';

// initialise the connection
TypedSurQL.Init(env.DB_URL, {
	websocket: false, auth: {
		username: env.DB_USER,
		password: env.DB_PASS
	},
	namespace: env.DB_NAMESPACE,
	database: env.DB_NAME
});

// wait until the connection is made
await TypedSurQL.Wait(5);
import { TypedSurQL, Model, Q, RelationEdge } from 'https://deno.land/x/typed_surql@v1.1.4/mod.ts';
import { Lemons } from "./lemons";

@Q.Table({ name: "eats" })
export class Eats extends RelationEdge<User, Lemons> { }

@Q.Table({ name: "user" })
export class User extends Model {
  @Q.Field({ index: { name: "username_idx", search: true } }) username!: string;
  @Q.Field() something!: string;
  @Q.Relation("->", Eats, "->", Lemons) readonly lemonsEaten!: Lemons[];
}

@Q.Table({ name: "session" })
export class Session extends Model {
  @Q.Field() active_expires!: number;
  @Q.Field() idle_expires!: number;
  @Q.Field() user!: User;
}

@Q.Table({ name: "key" })
export class Account extends Model {
  @Q.Field() hashed_password?: string | null;
  @Q.Field() key_id!: string;
  @Q.Field() user!: User;
}

// Defines the object types with only the properties
export type UserObject = Q.Static<User>;
export type SessionObject = Q.Static<Session>;
export type AccountObject = Q.Static<Account>;

// Perform queries

const result = await User.select("*", { fetch: ["lemonsEaten"]});

// query functions

import { query } from 'https://deno.land/x/typed_surql@v1.1.4/mod.ts';

// field param provides all surrealdb functions / operators and the table name as well allowing you to select the model properties:

query.queryModel(User, (q, field) => q`SELECT *, ${field.string.uppercase(field("username")).as("cap_username")} FROM ${field.TABLE} WHERE ${field("id")} = ....`)
// or you can do
User.query((q, { VALUE, TABLE, field }) => ....)....
  There is also an example folder with you can check out

Note There may be bugs

License

MIT


soyamiruku  

1.5.1

5 months ago

1.3.4

5 months ago

1.3.3

5 months ago

1.3.2

5 months ago

1.3.0

5 months ago

1.2.8

5 months ago

1.2.7

5 months ago

1.2.6

5 months ago

1.2.5

5 months ago

1.2.4

5 months ago

1.2.3

5 months ago

1.2.1

5 months ago

1.2.0

5 months ago

1.1.8

5 months ago

1.1.7

5 months ago

1.1.6

5 months ago

1.1.5

5 months ago

1.1.4

5 months ago

1.1.2

6 months ago

1.1.1

6 months ago

1.1.0

6 months ago

1.0.35

6 months ago

1.0.34

6 months ago

1.0.33

6 months ago

1.0.32

6 months ago

1.0.31

6 months ago

1.0.30

6 months ago

1.0.28

6 months ago

1.0.27

6 months ago

1.0.26

6 months ago

1.0.25

6 months ago

1.0.24

6 months ago

1.0.23

6 months ago

1.0.22

6 months ago

1.0.21

6 months ago

1.0.20

6 months ago

1.0.18

6 months ago

1.0.16

6 months ago