2.10.4 • Published 1 year ago
@soyamiruku/typed-surql-bun v2.10.4
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 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 '@soyamiruku/typed-surl';
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 '@soyamiruku/typed-surl';
// 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
2.10.4
1 year ago
2.10.3
1 year ago
2.10.2
2 years ago
2.0.3
2 years ago
2.0.5
2 years ago
2.0.4
2 years ago
2.0.7
2 years ago
2.0.6
2 years ago
2.0.9
2 years ago
2.0.8
2 years ago
2.10.1
2 years ago
2.10.0
2 years ago
2.0.2
2 years ago
2.0.1
2 years ago
2.0.0
2 years ago
1.9.9
2 years ago
1.9.8
2 years ago
1.9.7
2 years ago
1.9.6
2 years ago
1.9.5
2 years ago
1.9.1
2 years ago
1.9.0
2 years ago
1.9.4
2 years ago
1.9.3
2 years ago
1.9.2
2 years ago
1.8.9
2 years ago
1.8.8
2 years ago
1.8.7
2 years ago
1.8.6
2 years ago
1.8.5
2 years ago
1.8.4
2 years ago
1.8.2
2 years ago
1.8.1
2 years ago
1.8.0
2 years ago
1.8.3
2 years ago
1.7.3
2 years ago
1.7.2
2 years ago
1.7.1
2 years ago
1.7.0
2 years ago
1.7.9
2 years ago
1.7.8
2 years ago
1.6.9
2 years ago
1.7.7
2 years ago
1.6.8
2 years ago
1.6.7
2 years ago
1.7.5
2 years ago
1.6.6
2 years ago
1.7.4
2 years ago
1.6.5
2 years ago
1.6.4
2 years ago
1.6.0
2 years ago
1.5.9
2 years ago
1.5.8
2 years ago
1.5.7
2 years ago
1.5.6
2 years ago
1.5.5
2 years ago
1.5.4
2 years ago
1.5.3
2 years ago
1.5.1
2 years ago
1.5.0
2 years ago